Session Lifecycle
MCP session initialization, capability negotiation, and lifecycle management in our HTTP-based implementation
Session Initialization
Our MCP server uses a two-step initialization process over HTTP:
- Initialize Request: Client sends
initialize
method with protocol version and capabilities - Initialized Notification: Client confirms readiness with
notifications/initialized
Initialize Request
The client initiates a session by sending an initialize
request:
Initialize Response
The server responds with its capabilities and information:
The server includes a Mcp-Session-Id
header in the response for session tracking.
Initialized Notification
After receiving the initialize response, the client MUST send an initialized
notification:
This notification MUST include the Mcp-Session-Id
header from the initialize response.
Lifecycle Rules
- The client SHOULD NOT send requests other than pings before the server responds to
initialize
- The server SHOULD NOT send requests other than pings before receiving
notifications/initialized
- All subsequent requests MUST include the
Mcp-Session-Id
header
Version Negotiation
The client MUST send a protocol version in the initialize
request. Our server supports:
"2025-03-26"
(current)"2024-11-05"
(legacy support)
If the server supports the requested version, it responds with the same version. Otherwise, it responds with its preferred supported version.
If the client doesn’t support the server’s response version, it SHOULD disconnect.
HTTP Implementation: All subsequent requests MUST include the
Mcp-Session-Id
header returned by the initialize method.
Capability Negotiation
Client and server capabilities establish which protocol features are available during the session.
Our Server Capabilities:
Capability | Support | Features |
---|---|---|
tools | ✅ | listChanged: true - Tool list change notifications |
resources | ✅ | subscribe: true, listChanged: true - Resource subscriptions and change notifications |
prompts | ✅ | listChanged: true - Prompt list change notifications |
completions | ✅ | Argument completion for prompts and resources |
Client Capabilities (optional):
roots
: Directory roots with change notificationssampling
: LLM sampling configuration
Session Management
Session State
Each session maintains:
- Session ID: Unique identifier for the session
- Protocol Version: Negotiated MCP protocol version
- Initialization Status: Whether
notifications/initialized
was received - Request ID Tracking: Ensures request ID uniqueness within the session
- Client Information: Name and version from initialize request
Session Termination
Sessions can be terminated by:
- Client Disconnect: HTTP connection closes
- Server Shutdown: Graceful server shutdown
- Timeout: Session inactivity timeout (configurable)
- Error: Unrecoverable protocol errors
Error Handling
Initialization Errors:
Common Error Codes:
-32600
: Invalid Request (malformed initialize request)-32602
: Invalid params (missing protocolVersion, unsupported version)-32603
: Internal error (server initialization failure)
Implementation Notes
HTTP Transport Specifics
- Session Headers:
Mcp-Session-Id
header required after initialization - Request ID Uniqueness: Enforced per session, not globally
- Batch Requests: Supported as per JSON-RPC 2.0 specification
- Notifications: Return HTTP 202 (Accepted) status code