Building and Debugging Your First MCP Server in .NET
MCP Server Demo
A barebones .NET 10 MCP (Model Context Protocol) server demonstrating how to expose tools for AI assistants like Claude Desktop, Cursor, and VS Code Continue.
Prerequisites
- .NET 10 SDK
- Node.js (for MCP Inspector testing)
Running the Server
cd src/McpServerDemo.WebApi
dotnet run
The server will start on http://localhost:5125 with the SSE endpoint at http://localhost:5125/sse.
Testing
Option 1: MCP Inspector (Browser)
npx @modelcontextprotocol/inspector
Open http://localhost:6274 and connect to http://localhost:5125/sse.
Option 2: MCP Explorer (Windows)
Download from https://mcp-explorer.com and connect to http://localhost:5125/sse.
Client Configuration
Claude Desktop
Edit %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"demo-docs": {
"command": "npx",
"args": ["mcp-remote", "http://localhost:5125/sse"]
}
}
}
Cursor
In Settings → MCP:
{
"mcpServers": {
"demo-docs": {
"url": "http://localhost:5125/sse",
"transport": "sse"
}
}
}
VS Code Continue
Create ~/.continue/mcpServers/demo-docs.yaml:
name: Demo Docs
version: 0.0.1
schema: v1
mcpServers:
- name: demo-docs
type: sse
url: http://localhost:5125/sse
Project Structure
McpServerDemo/
├── McpServerDemo.sln
└── src/
└── McpServerDemo.WebApi/
├── Program.cs # MCP server configuration
├── Tools/
│ └── SearchDocs.cs # MCP tool implementation
├── Services/
│ ├── IDocumentSearchService.cs
│ ├── DocumentSearchService.cs
│ ├── ILlmService.cs
│ └── LlmService.cs
└── Properties/
└── launchSettings.json
Extending
To add more tools, create a new class in the Tools folder with the [McpServerToolType] attribute and methods decorated with [McpServerTool].
[McpServerToolType]
public class MyNewTool
{
[McpServerTool]
[Description("Does something useful")]
public async Task<string> DoSomething(
[Description("Input parameter")] string input)
{
// Implementation
}
}
License
MIT