MCP Transports
Transports handle the communication layer between MCP clients (like Claude) and your application's MCP server.
Available Transports
stdio Transport
The standard input/output transport for CLI applications and desktop tools.
csharp
builder.Services.AddMcp(options =>
{
options.ServerName = "MyApp";
options.ServerVersion = "1.0.0";
options.Transport = McpTransportType.Stdio;
});Use Cases:
- CLI applications
- Desktop applications with Claude Code integration
- Process-based communication
How It Works:
- Client spawns your application as a subprocess
- JSON-RPC messages sent via stdin
- Responses written to stdout
- Logs/errors written to stderr
HTTP Transport (Future)
HTTP-based transport for web services and APIs.
WARNING
HTTP transport is planned but not yet implemented.
Platform Availability
| Transport | Desktop | WebAssembly |
|---|---|---|
| stdio | ✅ | ❌ |
| HTTP | Planned | Planned |
Configuring stdio
Basic Configuration
csharp
builder.Services.AddMcp(options =>
{
options.ServerName = "MyApp";
options.ServerVersion = "1.0.0";
});
// After build
app.Services.UseMcp();Starting the Server
The MCP server starts automatically when initialized. For desktop applications:
csharp
// Enable MCP via message bus
await messageBus.PublishAsync(new EnableMcpServerMessage());Message Format
MCP uses JSON-RPC 2.0 for communication:
Request:
json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "greet",
"arguments": {
"name": "World"
}
}
}Response:
json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [
{
"type": "text",
"text": "Hello, World!"
}
]
}
}Error Handling
Transport errors are handled at the server level:
csharp
// Tool not found
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32601,
"message": "Unknown tool: invalid_tool"
}
}Best Practices
- Use stdio for desktop — Most compatible with AI coding assistants
- Keep tools fast — Long-running tools should support cancellation
- Log to stderr — Stdout is reserved for MCP communication
- Handle disconnection — Clean up resources if the client disconnects
