Content
# MCP Servers — C# / .NET 9
C# conversions of the Python (`mcp`/FastMCP) and TypeScript (`@modelcontextprotocol/sdk`) MCP server implementations in this repository.
All projects target **.NET 9** and use the official [`ModelContextProtocol`](https://www.nuget.org/packages/ModelContextProtocol) NuGet SDK.
## Prerequisites
- [.NET 9 SDK](https://dotnet.microsoft.com/download/dotnet/9.0)
---
## How to Build
Build all projects at once from this folder:
```bash
dotnet build Mcp.sln
```
Or build a single project:
```bash
dotnet build Mcp.Basic/Mcp.Basic.csproj
```
---
## How to Run
### stdio servers (Basic, WithResources, WithPrompts)
These servers communicate over standard input/output and are designed to be launched by an MCP client (e.g. Claude Desktop, VS Code Copilot).
**Run directly:**
```bash
dotnet run --project Mcp.Basic
dotnet run --project Mcp.WithResources
dotnet run --project Mcp.WithPrompts
```
**Claude Desktop / MCP client config (`mcp.json`):**
```json
{
"mcpServers": {
"binance-basic": {
"command": "dotnet",
"args": ["run", "--project", "C:/Code/mcp-experiments/csharp_mcp/Mcp.Basic"]
},
"binance-full": {
"command": "dotnet",
"args": ["run", "--project", "C:/Code/mcp-experiments/csharp_mcp/Mcp.WithPrompts"]
}
}
}
```
For production, publish first for faster startup:
```bash
dotnet publish Mcp.WithPrompts -c Release -o ./publish/WithPrompts
```
Then point the client at the published `.exe`.
### HTTP server (Mcp.Http)
```bash
dotnet run --project Mcp.Http
```
Server starts at `http://0.0.0.0:8000`. MCP clients connect to `http://localhost:8000/mcp`.
---
## MCP Primitives Map
### Tools (all projects)
| C# Method | MCP Tool Name | Description |
|---|---|---|
| `Tools.GetPrice` | `get_price` | Current price from |
| `Tools.GetPricePriceChange` | `get_price_price_change` | 24-hour price change |
### Resources (WithResources, WithPrompts)
| URI | Description |
|---|---|
| `file://activity.log` | Log of all `get_price` calls |
| `resource://crypto_price/{symbol}` | Live price for any symbol |
### Prompts (WithPrompts only)
| Prompt Name | Parameters | Description |
|---|---|---|
| `executive_summary` | _(none)_ | BTC + ETH executive summary |
| `crypto_summary` | `crypto` | Summary for any crypto asset |
---
## Python → C# Patterns
| Python (FastMCP) | C# (ModelContextProtocol SDK) |
|---|---|
| `@mcp.tool()` decorator | `[McpServerTool]` attribute on method inside `[McpServerToolType]` class |
| `@mcp.resource("uri")` decorator | `[McpServerResource(UriTemplate="uri")]` attribute |
| `@mcp.prompt()` decorator | `[McpServerPrompt]` attribute returning `ChatMessage` |
| `mcp.run(transport="stdio")` | `.WithStdioServerTransport()` + `Host.RunAsync()` |
| `mcp.run(transport="streamable-http")` | `.WithHttpTransport()` + `app.MapMcp()` |
| `FastMCP(host="0.0.0.0", port=8000)` | `builder.WebHost.UseUrls("http://0.0.0.0:8000")` |