This project contains a .NET web app implementation of a Model Context Protocol (MCP) server. The application is designed to be deployed to Azure App Service.
The MCP server provides an API that follows the Model Context Protocol specification, allowing AI models to request additional context during inference.
- Complete implementation of the MCP protocol in C#/.NET using MCP csharp-sdk
- Azure App Service integration
- Custom tools support
src/
- Contains the main C# project filesProgram.cs
- The entry point for the MCP serverTools/
- Contains custom tools that can be used by models via the MCP protocolMultiplicationTool.cs
- Example tool that performs multiplication operationsTemperatureConverterTool.cs
- Tool for converting between Celsius and FahrenheitWeatherTools.cs
- Tools for retrieving weather forecasts and alerts
infra/
- Contains Azure infrastructure as code using Bicepmain.bicep
- Main infrastructure definitionresources.bicep
- Resource definitionsmain.parameters.json
- Parameters for deployment
- Azure Developer CLI
- .NET 9 SDK
- For local development with VS Code:
- MCP C# SDK:
dotnet add package ModelContextProtocol --prerelease
- Clone this repository
- Navigate to the project directory
cd src
- Run the project:
dotnet run
- The MCP server will be available at
https://localhost:5000
- When you're done, press Ctrl+C in the terminal to stop the app
- Add MCP Server from command palette and add the URL to your running server's HTTP endpoint:
http://0.0.0.0:5000
- List MCP Servers from command palette and start the server
- In Copilot chat agent mode, enter a prompt to trigger the tool:
Multiply 3423 and 5465
- When prompted to run the tool, consent by clicking Continue
You can ask things like:
- What's the weather forecast in NYC?
- Are there any weather alerts in California?
- In a new terminal window, install and run MCP Inspector:
npx @modelcontextprotocol/inspector
- CTRL+click the URL displayed by the app (e.g. http://0.0.0.0:5173/#resources)
- Set the transport type to
HTTP
- Set the URL to your running server's HTTP endpoint and Connect:
http://0.0.0.0:5000
- List Tools, click on a tool, and Run Tool
-
Login to Azure:
azd auth login
-
Initialize your environment:
azd env new
-
Deploy the application:
azd up
This will:
- Build the .NET application
- Provision Azure resources defined in the Bicep templates
- Deploy the application to Azure App Service
Use the web app's URL:
https://<webappname>.azurewebsites.net
Follow the same process as with the local app, but use your App Service URL:
https://<webappname>.azurewebsites.net
When you're done working with your app and related resources, you can use this command to delete the function app and its related resources from Azure and avoid incurring any further costs:
azd down
The project includes a sample tool in the Tools
directory:
MultiplicationTool.cs
- A simple tool that demonstrates how to implement MCP tools
To add new tools:
- Create a new class in the
Tools
directory - Implement the MCP tool interface
- Register the tool in
Program.cs