Model Context Protocol Specification
The comprehensive architectural breakdown of MCP: connection lifecycles, JSON-RPC 2.0 wire framing, primitives (Tools, Resources, Prompts, Roots, Sampling), and enterprise sandboxing policies.
JSON-RPC 2.0 Protocol Payloads
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {
"roots": {
"listChanged": true
},
"sampling": {}
},
"clientInfo": {
"name": "ClaudeDesktop",
"version": "0.8.2"
}
}
}Core Protocol Primitives
The 5 essential capabilities negotiated between hosts and servers.
Tools
Functions exposed by the server that AI models can discover and invoke with validated JSON arguments.
Resources
Read-only context data (files, database schemas, API specs, log streams) exposed via standard URI templates.
Prompts
Pre-engineered prompt templates and workflows registered by servers to standardize complex multi-step reasoning tasks.
Roots
Defines the explicit filesystem boundaries and workspace folders that the server is permitted to access.
Dynamic Sampling
Enables an MCP server to request LLM generations back through the client, allowing nested agentic intelligence.
Transports & Wire Formats
Comparing process-isolated local transports with remote streaming connections.
STDIO (Standard I/O)
Local SubprocessThe host spawns the server as a child process. Messages are sent via newline-delimited UTF-8 JSON-RPC strings over STDIN and STDOUT.
- STDOUT is exclusively reserved for valid JSON-RPC frames.
- Server debug logs must be routed to STDERR.
- Process lifecycle is strictly tied to host application session.
SSE (Server-Sent Events) + HTTP POST
Remote / CloudServer streams events to client via HTTP GET /sse, while client posts JSON-RPC payloads via HTTP POST to the returned endpoint URI.
- Initial GET /sse handshake returns endpoint URI event with session ID.
- Requires keep-alive ping comments every 15-30s to prevent reverse proxy drop.
- Supports multi-client concurrent connections over HTTP/2 or HTTP/1.1.
Streamable HTTP / WebSockets
High PerformanceModern streaming transport utilizing full-duplex HTTP streaming or WebSocket frames for microservice architectures.
- Optimized for Kubernetes clusters and container meshes.
- Supports binary multiplexing and zero-copy JSON parsing.
State Machine & Handshake Lifecycle
Sequential handshake from initialization through normal operations to teardown.
Initialize Request
Client -> ServerinitializeNegotiates protocol version, declares host capabilities (roots, sampling), and shares client info.
Initialize Response
Server -> ClientresultServer acknowledges protocol version, returns server capabilities (tools, resources, prompts), and server info.
Initialized Notification
Client -> Servernotifications/initializedHandshake completed. Server is now permitted to send notifications and handle operational requests.
Operational Phase
Bidirectionaltools/call, resources/read, ...Model executes tools, reads resources, triggers prompts, and exchanges heartbeats via ping.
Teardown
Client / Serverclose / SIGTERMGraceful termination of subprocess pipes or SSE streaming connections.
Enterprise Security & Sandboxing Matrix
Safeguards protecting against arbitrary code execution, credential leakage, and SSRF.
Explicit Roots Boundary
Filesystem servers MUST strictly enforce path scoping within roots/list boundaries to prevent directory traversal attacks (e.g. ../../etc/passwd).
Confirmation Gates for Destructive Actions
Host clients should render interactive user confirmation prompts before executing mutating tools (e.g. DB DELETE, Git Push, Shell exec).
Environment Variable Isolation
Pass only declared server credentials in the env block; never leak host system parent environment variables.
SSRF & Network Egress Restrictions
Fetch and web scraping servers should block internal private IP ranges (127.0.0.1, 10.0.0.0/8, 169.254.169.254) to prevent metadata service exploits.