paulsohal1981/POCDotNetMCPServer
If you are the rightful owner of POCDotNetMCPServer 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.
This document provides a comprehensive overview of a .NET 9 implementation of the Model Context Protocol (MCP) server, which supports HTTP transport using JSON-RPC.
.NET MCP Server with HTTP JSON-RPC Transport# MCP Server
A .NET 9 implementation of the Model Context Protocol (MCP) server that supports HTTP transport using JSON-RPC. This server is compatible with ChatGPT and other MCP clients that support HTTP-based communication.This README was created using the C# MCP server project template.
It demonstrates how you can easily create an MCP server using C# and publish it as a NuGet package.
🚀 Features
The MCP server is built as a self-contained application and does not require the .NET runtime to be installed on the target machine.
-
JSON-RPC over HTTP: Implements the official MCP HTTP transport specificationHowever, since it is self-contained, it must be built for each target platform separately.
-
MCP Protocol 2025-06-18: Full support for the latest MCP protocol versionBy default, the template is configured to build for:
-
ChatGPT Compatible: Ready to integrate with ChatGPT and web-based MCP clients*
win-x64 -
CORS Enabled: Configured for cross-origin requests*
win-arm64 -
ASP.NET Core: Built on modern .NET web framework*
osx-arm64 -
Docker Ready: Containerizable for easy deployment*
linux-x64
linux-arm64
🛠️ Quick Start* linux-musl-x64
PrerequisitesIf your users require more platforms to be supported, update the list of runtime identifiers in the project's <RuntimeIdentifiers /> element.
- .NET 9.0 SDK or laterSee aka.ms/nuget/mcp/guide for the full guide.
Installation & RunningPlease note that this template is currently in an early preview stage. If you have feedback, please take a brief survey.
-
Clone the repository:## Checklist before publishing to NuGet.org
git clone https://github.com/paulsohal1981/POCDotNetMCPServer.git- Test the MCP server locally using the steps below. cd POCDotNetMCPServer- Update the package metadata in the .csproj file, in particular the `<PackageId>`. ```- Update `.mcp/server.json` to declare your MCP server's inputs.
- See configuring inputs for more details.
-
Build the project:- Pack the project using
dotnet pack.dotnet buildThe `bin/Release` directory will contain the package file (.nupkg), which can be [published to NuGet.org](https://learn.microsoft.com/nuget/nuget-org/publish-a-package).
Developing locally
-
Run the server:
```bashTo test this MCP server from source code (locally) without using a built MCP server package, you can configure your IDE to run the project directly using
dotnet run.dotnet run
Or specify a custom port:{ ```bash "servers": { PORT=9001 dotnet run "POCDotNetMCPServer": { ``` "type": "stdio", "command": "dotnet", -
Verify it's running: "args": [
curl http://localhost:8080/health "--project", # Expected: "MCP Server is running via HTTP with JSON-RPC" "<PATH TO PROJECT DIRECTORY>" ``` ] }
📡 API Endpoints }
}
Main MCP Endpoint```
-
URL:
POST /mcp -
Content-Type:
application/json## Testing the MCP Server -
Protocol: JSON-RPC 2.0
-
MCP Version: 2025-06-18Once configured, you can ask Copilot Chat for a random number, for example,
Give me 3 random numbers. It should prompt you to use theget_random_numbertool on thePOCDotNetMCPServerMCP server and show you the results.
Health Check## Publishing to NuGet.org
-
URL:
GET /health -
Response: Plain text status message1. Run
dotnet pack -c Releaseto create the NuGet package
- Publish to NuGet.org with
dotnet nuget push bin/Release/*.nupkg --api-key <your-api-key> --source https://api.nuget.org/v3/index.json
🔧 MCP Methods
Using the MCP Server from NuGet.org
1. Initialize
Establishes the MCP session and exchanges capabilities.Once the MCP server package is published to NuGet.org, you can configure it in your preferred IDE. Both VS Code and Visual Studio use the dnx command to download and install the MCP server package from NuGet.org.
```json- VS Code: Create a <WORKSPACE DIRECTORY>/.vscode/mcp.json file
{- Visual Studio: Create a <SOLUTION DIRECTORY>\.mcp.json file
"jsonrpc": "2.0",
"id": 1,For both VS Code and Visual Studio, the configuration file uses the following server definition:
"method": "initialize",
"params": {```json
"protocolVersion": "2025-06-18",{
"capabilities": {}, "servers": {
"clientInfo": { "POCDotNetMCPServer": {
"name": "your-client", "type": "stdio",
"version": "1.0.0" "command": "dnx",
} "args": [
} "
} "--version",
"--yes"
### 2. Tools List ]
Retrieves available tools and their schemas. }
}
```json}
{```
"jsonrpc": "2.0",
"id": 2,## More information
"method": "tools/list"
}.NET MCP servers use the [ModelContextProtocol](https://www.nuget.org/packages/ModelContextProtocol) C# SDK. For more information about MCP:
3. Tools Call- Protocol Specification
Executes a specific tool with provided arguments.- GitHub Organization
{
"jsonrpc": "2.0",- [Use MCP servers in VS Code (Preview)](https://code.visualstudio.com/docs/copilot/chat/mcp-servers)
"id": 3,- [Use MCP servers in Visual Studio (Preview)](https://learn.microsoft.com/visualstudio/ide/mcp-servers)
"method": "tools/call",
"params": {
"name": "get_random_number",
"arguments": {
"min": 1,
"max": 100
}
}
}
🎲 Available Tools
get_random_number
Generates a random number within specified bounds.
Parameters:
min(integer, optional): Minimum value (inclusive), default: 0max(integer, optional): Maximum value (exclusive), default: 100
Example Response:
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{
"type": "text",
"text": "Generated random number: 42 (between 1 and 100)"
}
]
}
}
🌐 ChatGPT Integration
To use this server with ChatGPT:
-
Start the server locally:
PORT=9001 dotnet run -
Expose via tunnel (using ngrok):
ngrok http 9001 -
Configure in ChatGPT: Use the ngrok URL +
/mcpendpoint:https://abc123.ngrok-free.app/mcp
🧪 Testing
Manual Testing with curl
# Health check
curl -X GET http://localhost:8080/health
# Initialize session
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-06-18"}}'
# List available tools
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}'
# Generate random number
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "get_random_number", "arguments": {"min": 1, "max": 10}}}'
🔨 Development
Adding New Tools
-
Create tool methods in
RandomNumberTools.csor create new tool classes:[McpServerTool] [Description("Your tool description")] public string YourNewTool([Description("Parameter description")] string param) { // Tool implementation return "result"; } -
Register the tool class in
Program.cs:builder.Services.AddSingleton<YourNewToolClass>(); -
Update the handlers in
Program.cs:- Add tool to
HandleToolsListmethod - Add handling logic to
HandleToolsCallmethod
- Add tool to
Project Structure
POCDotNetMCPServer/
├── Program.cs # Main application entry point
├── Tools/
│ └── RandomNumberTools.cs # Tool implementations
├── POCDotNetMCPServer.csproj # Project configuration
├── README.md # This file
└── .gitignore # Git ignore rules
📦 Dependencies
- Microsoft.AspNetCore.App - Web framework
- ModelContextProtocol - MCP SDK for .NET
- Swashbuckle.AspNetCore - API documentation
🚢 Deployment
Using Docker (Future Enhancement)
FROM mcr.microsoft.com/dotnet/aspnet:9.0
COPY bin/Release/net9.0/publish/ App/
WORKDIR /App
ENTRYPOINT ["dotnet", "POCDotNetMCPServer.dll"]
Environment Variables
PORT: Server port (default: 8080)ASPNETCORE_ENVIRONMENT: Environment setting
📋 Requirements
- .NET 9.0 or later
- Compatible with Windows, macOS, and Linux
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.