Skip to content

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:

  1. Client spawns your application as a subprocess
  2. JSON-RPC messages sent via stdin
  3. Responses written to stdout
  4. 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

TransportDesktopWebAssembly
stdio
HTTPPlannedPlanned

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

  1. Use stdio for desktop — Most compatible with AI coding assistants
  2. Keep tools fast — Long-running tools should support cancellation
  3. Log to stderr — Stdout is reserved for MCP communication
  4. Handle disconnection — Clean up resources if the client disconnects