POCDotNetMCPServer

paulsohal1981/POCDotNetMCPServer

3.2

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.

Tools
1
Resources
0
Prompts
0

.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.

Installation & RunningPlease note that this template is currently in an early preview stage. If you have feedback, please take a brief survey.

  1. 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.
    
    
  1. 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

  1. 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",
    
    
  2. 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 the get_random_number tool on the POCDotNetMCPServer MCP server and show you the results.

Health Check## Publishing to NuGet.org

  • URL: GET /health

  • Response: Plain text status message1. Run dotnet pack -c Release to create the NuGet package

  1. 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: 0
  • max (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:

  1. Start the server locally:

    PORT=9001 dotnet run
    
  2. Expose via tunnel (using ngrok):

    ngrok http 9001
    
  3. Configure in ChatGPT: Use the ngrok URL + /mcp endpoint:

    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

  1. Create tool methods in RandomNumberTools.cs or create new tool classes:

    [McpServerTool]
    [Description("Your tool description")]
    public string YourNewTool([Description("Parameter description")] string param)
    {
        // Tool implementation
        return "result";
    }
    
  2. Register the tool class in Program.cs:

    builder.Services.AddSingleton<YourNewToolClass>();
    
  3. Update the handlers in Program.cs:

    • Add tool to HandleToolsList method
    • Add handling logic to HandleToolsCall method

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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔗 Related Links