Expand description
§HTTP MCP Server
This crate provides HTTP transport for Model Context Protocol (MCP) servers. It supports both modern Streamable HTTP (2025-03-26+) and legacy HTTP+SSE transports for maximum compatibility with all MCP clients.
§Supported Transports
- Streamable HTTP (2025-03-26+): Recommended for production deployments
- HTTP+SSE (2024-11-05): Legacy transport for backwards compatibility
§Features
- Automatic protocol version detection and routing
- CORS support for browser-based clients
- Session management with cryptographically secure IDs
- Graceful error handling and JSON-RPC 2.0 compliance
Re-exports§
pub use cors::CorsLayer;
pub use handler::McpHttpHandler;
pub use notification_bridge::BroadcastError;
pub use notification_bridge::NotificationBroadcaster;
pub use notification_bridge::StreamManagerNotificationBroadcaster;
pub use protocol::extract_last_event_id;
pub use protocol::extract_protocol_version;
pub use protocol::extract_session_id;
pub use protocol::McpProtocolVersion;
pub use server::HttpMcpServer;
pub use server::HttpMcpServerBuilder;
pub use server::ServerConfig;
pub use server::ServerStats;
pub use session_handler::SessionMcpHandler;
pub use session_handler::SessionSseStream;
pub use stream_manager::StreamConfig;
pub use stream_manager::StreamError;
pub use stream_manager::StreamManager;
pub use stream_manager::StreamStats;
pub use streamable_http::StreamableHttpContext;
pub use streamable_http::StreamableHttpHandler;
Modules§
- completion
- MCP Completion Protocol Types
- cors
- CORS (Cross-Origin Resource Sharing) support
- elicitation
- MCP Elicitation Protocol Types
- handler
- HTTP request handler for MCP protocol
- initialize
- MCP Initialize Protocol Types
- json_
rpc - JSON-RPC 2.0 Implementation for MCP 2025-06-18
- json_
rpc_ responses - JSON-RPC 2.0 response builders for HTTP transport
- logging
- MCP Logging Protocol Types
- mcp_
session - Streamable HTTP session management for MCP transport
- meta
- _meta Field Support for MCP 2025-06-18
- notification_
bridge - Notification Bridge - Connects NotificationBroadcaster to StreamManager
- notifications
- MCP Notifications Protocol Types
- param_
extraction - Parameter extraction utilities for MCP protocol
- ping
- MCP Ping Protocol Types
- prompts
- MCP Prompts Protocol Types
- protocol
- MCP Protocol Version Detection and Features
- resources
- MCP Resources Protocol Types
- roots
- MCP Roots Protocol Types
- sampling
- MCP Sampling Protocol Types
- schema
- JSON Schema Support for MCP
- server
- HTTP MCP Server with SessionStorage integration
- session_
handler - JSON-RPC 2.0 over HTTP handler for MCP requests with SessionStorage integration
- sse
- Server-Sent Events (SSE) support for MCP
- stream_
manager - Enhanced Stream Manager with MCP 2025-06-18 Resumability
- streamable_
http - Streamable HTTP Transport for MCP 2025-06-18
- tools
- MCP Tools Protocol Types
- traits
- Traits for JSON-RPC types as per MCP specification (2025-06-18)
- version
- MCP Protocol Version Support
Macros§
- impl_
serde_ extractor - Macro to implement SerdeParamExtractor for any Params type that implements Deserialize
Structs§
- Call
Tool Request - Complete tools/call request (matches TypeScript CallToolRequest interface)
- Call
Tool Result - Result for tools/call (per MCP spec)
- Cancelled
Notification - Method: “notifications/cancelled”
- Client
Capabilities - Capabilities that a client may support
- Elicit
Create Params - Parameters for elicitation/create request (per MCP spec)
- Elicit
Create Request - Complete elicitation/create request (matches TypeScript ElicitRequest interface)
- Elicit
Result - The client’s response to an elicitation request (per MCP spec)
- Elicitation
Builder - Builder for creating common elicitation patterns
- Elicitation
Schema - Restricted schema for elicitation (only primitive types, no nesting) - per MCP spec
- Empty
Params - Empty
Result - Empty result for successful operations (per MCP spec)
- GetPrompt
Request - Complete prompts/get request (matches TypeScript GetPromptRequest interface)
- GetPrompt
Result - Result for prompts/get (per MCP spec)
- Implementation
- Describes the name and version of an MCP implementation
- Initialize
Request - Parameters for initialize request
- Initialize
Result - Result payload for initialize (per MCP spec)
- Initialized
Notification - Method: “notifications/initialized”
- Json
RpcDispatcher - JSON-RPC method dispatcher
- Json
RpcError - JSON-RPC 2.0 error object
- Json
RpcNotification - A JSON-RPC 2.0 notification (no response expected)
- Json
RpcRequest - A standard JSON-RPC 2.0 request
- Json
RpcResponse - A standard JSON-RPC 2.0 response
- List
Prompts Request - Complete prompts/list request (matches TypeScript ListPromptsRequest interface)
- List
Prompts Result - Result for prompts/list (per MCP spec)
- List
Resources Request - Complete resources/list request (matches TypeScript ListResourcesRequest interface)
- List
Resources Result - Result for resources/list (per MCP spec)
- List
Tools Request - Complete tools/list request (matches TypeScript ListToolsRequest interface)
- List
Tools Result - Result for tools/list (per MCP spec) - extends PaginatedResult
- Logging
Message Notification - Method: “notifications/message”
- Logging
Message Notification Params - Meta
- Structured _meta field for MCP 2025-06-18
- Meta
Cursor - Cursor for pagination support
- Notification
- Base notification structure following MCP TypeScript specification
- Notification
Params - Base notification parameters that can include _meta
- Paginated
Response - Helper for pagination responses
- Ping
Request - Request for ping (per MCP spec)
- Progress
Notification - Method: “notifications/progress”
- Progress
Notification Params - Progress
Response - Helper for progress responses
- Progress
Token - Progress token for tracking long-running operations
- Prompt
- A prompt descriptor (matches TypeScript Prompt interface exactly)
- Prompt
Argument - Argument definition for prompts (extends BaseMetadata per MCP spec)
- Prompt
List Changed Notification - Method: “notifications/prompts/list_changed” (per MCP spec)
- Prompt
Message - Message content for prompts (matches MCP PromptMessage interface exactly)
- Read
Resource Request - Complete resources/read request (matches TypeScript ReadResourceRequest interface)
- Read
Resource Result - Result for resources/read (per MCP spec)
- Request
Params - JSON-RPC
params
object with optional_meta
and method-specific arguments - Resource
- A resource descriptor (matches TypeScript Resource interface) Resource extends BaseMetadata, so it includes name and title fields
- Resource
List Changed Notification - Method: “notifications/resources/list_changed” (per MCP spec)
- Resource
Subscription - Resource subscription parameters
- Resource
Updated Notification - Method: “notifications/resources/updated”
- Resource
Updated Notification Params - Result
With Meta - A generic result wrapper that combines data with optional _meta information
- Roots
List Changed Notification - Method: “notifications/roots/list_changed” (per MCP spec)
- Server
Capabilities - Capabilities that a server may support
- Subscribe
Request - Complete resources/subscribe request (per MCP spec)
- Tool
- Tool definition
- Tool
List Changed Notification - Method: “notifications/tools/list_changed” (per MCP spec)
- Tool
Schema - JSON Schema definition for tool input/output (matches TypeScript spec exactly) Must be an object with type: “object”, properties, and required fields
- Unsubscribe
Request - Complete resources/unsubscribe request (per MCP spec)
Enums§
- Elicit
Action - User action in response to elicitation
- Http
McpError - HTTP MCP specific errors
- Json
RpcMessage - Unified JSON-RPC message type
- Json
Schema - A JSON Schema definition
- Legacy
Request Params - Parameters for a JSON-RPC request
- McpError
- MCP-specific errors
- McpVersion
- Supported MCP protocol versions
- Primitive
Schema Definition - Restricted schema definitions that only allow primitive types without nested objects or arrays (per MCP spec).
- Request
Id - A uniquely identifying ID for a JSON-RPC request. Can be a string or a number, but never null.
- Resource
Content - Union type for resource contents (matches TypeScript union)
- Response
Result - Result data for a JSON-RPC response
- String
Format - String format constraints
- Tool
Result - Content item types that tools can return
Constants§
- CURRENT_
VERSION - The current MCP protocol version implemented by this crate
- MCP_
VERSION - The MCP protocol version implemented by this crate
Traits§
- HasData
- HasData
Param - HasMeta
- HasMeta
Param - HasProgress
Token Param - Json
RpcHandler - Trait for handling JSON-RPC method calls
- Json
RpcNotification Trait - Json
RpcRequest Trait - Json
RpcResponse Trait - Params
- RpcResult
- With
Meta - Trait for types that can include _meta fields