Documentation Index
Fetch the complete documentation index at: https://mintlify.com/modelcontextprotocol/csharp-sdk/llms.txt
Use this file to discover all available pages before exploring further.
Architecture
The MCP C# SDK is designed with a modular, layered architecture that separates concerns and provides flexibility for different deployment scenarios.Package Structure
The SDK is distributed as three NuGet packages, each building on the previous:ModelContextProtocol.Core
ModelContextProtocol.Core
The foundational package providing core protocol implementation with minimal dependencies.Use when:
- You need only client functionality
- You’re building low-level server implementations
- You want minimal dependencies
ModelContextProtocol.Protocol- Protocol types and JSON-RPC messagesModelContextProtocol.Client- Client implementation and transportsModelContextProtocol.Server- Low-level server primitives
ModelContextProtocol
ModelContextProtocol
The main package adding hosting, dependency injection, and attribute-based discovery.Use when:
- Building stdio-based servers
- You want hosting and DI support
- You need attribute-based tool/prompt/resource registration
AddMcpServer()extension forIServiceCollection- Attribute-based discovery (
[McpServerTool],[McpServerPrompt],[McpServerResource]) IHostedServiceintegration- Stdio server transport configuration
ModelContextProtocol.CoreModelContextProtocol.AspNetCore
ModelContextProtocol.AspNetCore
ASP.NET Core integration for HTTP-based MCP servers.Use when:
- Building HTTP-based servers (Streamable HTTP or SSE)
- You need ASP.NET Core middleware integration
- You want session management and state persistence
MapMcp()endpoint routing- HTTP transport configuration
- Session management for stateless HTTP servers
- Distributed cache support for event streams
ModelContextProtocolCore Architecture Layers
The SDK follows a layered architecture:Protocol Layer
Defines the core MCP protocol types and JSON-RPC message structures. Key types:JsonRpcMessage- Base message typeJsonRpcRequest- Request messagesJsonRpcResponse- Response messagesJsonRpcNotification- Notification messages- Protocol capability types (
ClientCapabilities,ServerCapabilities) - Content types (
TextContentBlock,ImageContentBlock,EmbeddedResourceBlock)
ModelContextProtocol.Protocol namespace in Core package
Transport Layer
Abstracts communication mechanisms between clients and servers. Core interface:| Transport | Client | Server | Use Case |
|---|---|---|---|
StdioClientTransport | ✓ | - | Launch child process servers |
StdioServerTransport | - | ✓ | Stdio-based servers |
HttpClientTransport | ✓ | - | Connect to HTTP servers |
StreamableHttpServerTransport | - | ✓ | ASP.NET Core Streamable HTTP |
SseClientSessionTransport | ✓ | - | Legacy SSE clients |
SseResponseStreamTransport | - | ✓ | Legacy SSE servers |
ModelContextProtocol.Client and ModelContextProtocol.Server namespaces
Session Layer
Manages the lifecycle of MCP sessions and handles JSON-RPC message routing. Core class:McpSessionHandler
Responsibilities:
- Protocol version negotiation
- Request/response correlation
- Notification dispatching
- Cancellation propagation
- Telemetry and diagnostics
McpSession
Provides common functionality for both clients and servers:
High-Level API
Provides strongly-typed, feature-specific APIs for clients and servers.Server Handler Architecture
Servers use a handler-based architecture for processing requests:Handler Types
- Request Handlers
- Notification Handlers
- Primitives (Tools/Prompts/Resources)
Process incoming requests and return responses.Examples:
- Tool invocation handler
- Resource read handler
- Prompt get handler
Filter Pipeline
Filters provide cross-cutting concerns: Message Filters - Apply to all messages (requests, responses, notifications)- Logging and telemetry
- Authentication/authorization
- Request validation
- Error handling
- Performance monitoring
Dependency Injection Integration
The SDK integrates deeply with Microsoft.Extensions.DependencyInjection:McpServerOptions.ScopeRequests = true). This ensures:
- Scoped services are isolated per request
- Proper disposal of scoped resources
- Thread-safe service resolution
Protocol Version Support
The SDK supports multiple protocol versions with automatic negotiation: Supported versions:2024-11-05(initial release)2025-03-262025-06-182025-11-25(latest, adds session resumption)
- Client sends
initializerequest with desired version - Server responds with matching or compatible version
- Both sides use negotiated version for the session
The
McpSessionHandler.LatestProtocolVersion constant defines the newest version: "2025-11-25"Threading and Concurrency
Message Processing:- Each session has a dedicated message processing task
- Messages are read from
ITransport.MessageReader(aChannelReader<JsonRpcMessage>) - Handlers execute concurrently unless constrained by user code
- Requests include automatic cancellation token propagation
- Clients can send
notifications/cancelledto request server-side cancellation - Servers track in-flight requests and can cancel handlers
McpClientandMcpServerare thread-safe for concurrent requests- Transports handle message serialization synchronization
- Pending request tracking uses
ConcurrentDictionary
Telemetry and Diagnostics
The SDK emits telemetry usingSystem.Diagnostics.Metrics:
Metrics:
mcp.client.session.duration- Client session lifetimemcp.server.session.duration- Server session lifetimemcp.client.operation.duration- Client request/notification durationmcp.server.operation.duration- Server handler duration
ILoggerFactory for diagnostic logging:
Next Steps
Client Concepts
Learn about client implementation and session management
Server Concepts
Understand server handler architecture
Transports
Explore transport options and configuration
Capabilities
Configure capability negotiation