yosmanovich/MCP-Demo
If you are the rightful owner of MCP-Demo and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Model Context Protocol (MCP) Server is a .NET implementation that provides an API for AI models to request additional context during inference, supporting both local and web-based deployments.
Model Context Protocol (MCP) Server and AI Client - .NET Implementation
This project contains two .NET app implementations of a Model Context Protocol (MCP) server; one runs in standard IO mode and another runs through a web application. The web application may 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.
The MCP tools are in a separate project. The tools are not complex; they show the basic struture of how a tool is developed and to provide a starting point for building additional tools. There is also a Tests project that demonstrates how to unit test each tool.
A simple AI Client exists that may be used to make Chat calls to your Azure AI service and to an MCP Server. This client shows the basic flow between the system, user, assistant, and tools.
Key Features
- Azure App Service integration
- Custom tools support
Project Structure
.vscode/- VS Code workspace filesmcp.json- The
src/- Contains the main C# project filesAI.Client/- The AI Client filesProgram.cs- The entry point for the AI ClientAIClient.cs- The logic for the AI Client
MCP.Local/- The MCP Local Server that runs via stdioProgram.cs- The entry point for the MCP Local Server
MCP.Server/- The MCP Server that runs via HTTP/HTTPSProgram.cs- The entry point for the MCP Server
MCP.Tools/- Contains custom tools that can be used by models via the MCP protocolEchoTools.cs- Tool for simple string echo testsMultiplicationTool.cs- Example tool that performs multiplication operationsTemperatureConverterTool.cs- Tool for converting between Celsius and Fahrenheit
MCP.Tools.Tests/- The unit tests for the MCP ToolsEchoToolsTests.cs- Unit Tests for the Echo ToolsMultiplicationToolTests.cs- Unit Tests for the Multiplication ToolTemperatureConverterToolTests.cs- Unit Tests for the Temperature Converter Tool
Prerequisites
-
For local development with VS Code:
-
For local development with docker:
-
An Azure Open AI Instance with a chat completion model deployed
-
MCP C# SDK:
dotnet add package ModelContextProtocol --prerelease
Local Development
Run the Server Locally
- Clone this repository
- Navigate to the project directory
cd src - Install required packages
dotnet restore - Run the project:
dotnet run - The MCP server will be available at
http://localhost:5000 - When you're done, press Ctrl+C in the terminal to stop the app
Creating a docker image
- Open terminal
- Navigate to MCP.Local;
cd .\src\MCP.Local\
- Build the docker container:
dotnet publish /t:PublishContainer
Testing the Available Tools
The server provides these tools:
- Multiplication:
Multiply- Multiplies two numbers - Temperature Conversion:
CelsiusToFahrenheit- Converts temperature from Celsius to FahrenheitFahrenheitToCelsius- Converts temperature from Fahrenheit to Celsius
Connect to the Local MCP Server
Using VS Code - Copilot Agent Mode
- Add MCP Server from command palette and add the URL to your running server's HTTP endpoint:
http://localhost: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:
- Convert 25 degrees Celsius to Fahrenheit
Using MCP Inspector
- In a new terminal window, install and run MCP Inspector:
npx @modelcontextprotocol/inspector - CTRL+click the URL displayed by the app (e.g. http://localhost:5173/#resources)
- Set the transport type to
HTTP - Set the URL to your running server's HTTP endpoint and Connect:
http://localhost:5000 - List Tools, click on a tool, and Run Tool
Deploy to Azure
-
Login to Azure:
azd auth login -
Initialize your environment:
azd env new -
Deploy the application:
azd upThis will:
- Build the .NET application
- Provision Azure resources defined in the Bicep templates
- Deploy the application to Azure App Service
Connect to Remote MCP Server
Using MCP Inspector
Use the web app's URL:
https://<webappname>.azurewebsites.net
Using VS Code - GitHub Copilot
Follow the same process as with the local app, but use your App Service URL:
https://<webappname>.azurewebsites.net
Run the AI Client
Modify the appsettings.json
- Set the AZURE_OPENAI ENDPOINT to your Azure Open AI endpoint
- Set the AZURE_OPENAI MODEL to a model you have deployed in Azure Open AI
- Set the MCP_SERVER URL to the MCP server that you are running
Modify the local secrets
- Set the AZURE_OPENAI API_KEY to your Azure Open AI API Key
Run the AI Client
Start the AI.Client project
dotnet run --project .\src\AI.Client\AI.Client.csproj
The client will connect to your MCP server and add all tools, notifying you in the console.
You can ask the LLM to provide information; if you provide a message that can be handled by one of the tools it will call the tool to get information from the tool and report that to you.
The application will run until you either type exit and hit enter or if you press enter with no other input.
You may clear the chat history by typing
clear
You can review the sytem prompt by typing
show prompt
You can change the sytem prompt by typing
set prompt
``` or
change prompt
If you enter an empty prompt, the tool will reset the prompt back to the default prompt / what was entered in appsettings.json.
Observe that the if the LLM has knowledge that conflicts with the tools, it will notify the user of that. This may be corrected via changes to the prompt, for example:
- "You are a math expert..."
- "You do not understand math..."
- "You are a facilitator..."
Additionally, if you modify the system prompt with calls to the tools; the AI Client should handle those tool calls as well as part of the conversation, for example:
- "Always convert the answer from the tool's response from fahrenheit to celsius at the end."
## Clean up resources
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:
```shell
azd down
Custom Tools
The project includes several sample tools in the MCP.Tools project:
EchoTool.cs- Performs basic string echo operationsMultiplicationTool.cs- Performs multiplication operationsTemperatureConverterTool.cs- Converts between Celsius and Fahrenheit
To add new tools:
- Create a new class in the
Toolsdirectory - Implement the MCP tool interface
- Register the tool in
Program.cs
References
This project is an amalgamation of several projects found on the web. Each did one thing right and this is meant to be an all-in-one, easy to consume project that discusses getting started with MCP all the way through deploying something to Azure and how it ties into both Copilot and a custom AI Client.
- Complete implementation of the MCP protocol in C#/.NET using MCP csharp-sdk
- Model Context Protocol (MCP) Server - .NET Implementation remote-mcp-webapp-dotnet