Base Protocol: Core JSON-RPC message types
Lifecycle Management: Connection initialization, capability negotiation, and session control
Server Features: Resources, prompts, and tools exposed by servers
Client Features: Sampling and root directory lists provided by clients
Utilities: Cross-cutting concerns like logging and argument completion
Auth
Authentication and authorization are not currently part of the core MCP specification, but we are considering ways to introduce them in future.
Lifecycle Phases
Initialization
The initialization phase MUST be the first interaction between client and server. During this phase, the client and server:
Establish protocol version compatibility
Exchange and negotiate capabilities
Share implementation details
The client MUST initiate this phase by sending an initialize request containing:
Protocol version supported
Client capabilities
Client implementation information
The server MUST respond with its own capabilities and information:
Sample client info
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {
"roots": {
"listChanged": true
},
"sampling": {}
},
"clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
}
}
}
Sample server info
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {
"logging": {},
"prompts": {
"listChanged": true
},
"resources": {
"subscribe": true,
"listChanged": true
},
"tools": {
"listChanged": true
}
},
"serverInfo": {
"name": "ExampleServer",
"version": "1.0.0"
}
}
}
The client SHOULD NOT send requests other than pings before the server has responded to the initialize request.
The server SHOULD NOT send requests other than pings and logging before receiving the initialized notification.
Version Negotiation
In the initialize request, the client MUST send a protocol version it supports. This SHOULD be the latest version supported by the client.
If the server supports the requested protocol version, it MUST respond with the same version. Otherwise, the server MUST respond with another protocol version it supports. This SHOULD be the latest version supported by the server.
If the client does not support the version in the server’s response, it SHOULD disconnect.
Error Handling
Implementations SHOULD be prepared to handle these error cases:
Protocol version mismatch
Failure to negotiate required capabilities
Initialize request timeout
Shutdown timeout
Implementations SHOULD implement appropriate timeouts for all requests, to prevent hung connections and resource exhaustion.
Example initialization error:
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32602,
"message": "Unsupported protocol version",
"data": {
"supported": ["2024-11-05"],
"requested": "1.0.0"
}
}
}
references:
https://spec.modelcontextprotocol.io/specification/basic/
No comments:
Post a Comment