Expand description
§HTTP MCP Server
Production HTTP transport layer for Model Context Protocol (MCP) servers.
Provides both modern Streamable HTTP and legacy HTTP+SSE transports with automatic protocol detection, CORS support, and session management for maximum compatibility.
§Installation
[dependencies]
turul-http-mcp-server = "0.2"
turul-mcp-server = "0.2"
§Supported Transports
- Streamable HTTP: Recommended for production deployments
- HTTP+SSE: 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
§Quick Start
use turul_http_mcp_server::HttpMcpServerBuilder;
use std::net::SocketAddr;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr: SocketAddr = "127.0.0.1:8080".parse()?;
let server = HttpMcpServerBuilder::new()
.bind_address(addr)
.cors(true)
.build();
println!("Server running on http://127.0.0.1:8080/mcp");
server.run().await?;
Ok(())
}
Re-exports§
pub use cors::CorsLayer;
pub use notification_bridge::BroadcastError;
pub use notification_bridge::NotificationBroadcaster;
pub use notification_bridge::StreamManagerNotificationBroadcaster;
pub use protocol::McpProtocolVersion;
pub use protocol::extract_last_event_id;
pub use protocol::extract_protocol_version;
pub use protocol::extract_session_id;
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
- Core MCP protocol types and error handling MCP Completion Protocol Types
- content
- Core MCP protocol types and error handling Content types for MCP 2025-06-18 specification
- cors
- CORS (Cross-Origin Resource Sharing) support
- elicitation
- Core MCP protocol types and error handling MCP Elicitation Protocol Types
- handler
- SSE stream body utilities for MCP protocol
- initialize
- Core MCP protocol types and error handling MCP Initialize Protocol Types
- json_
rpc - Core MCP protocol types and error handling JSON-RPC 2.0 Implementation for MCP 2025-06-18
- json_
rpc_ responses - JSON-RPC 2.0 response builders for HTTP transport
- logging
- Core MCP protocol types and error handling MCP Logging Protocol Types
- mcp_
session - Streamable HTTP session management for MCP transport
- meta
- Core MCP protocol types and error handling _meta Field Support for MCP 2025-06-18
- notification_
bridge - Notification Bridge - Connects NotificationBroadcaster to StreamManager
- notifications
- Core MCP protocol types and error handling MCP Notifications Protocol Types
- param_
extraction - Core MCP protocol types and error handling Parameter extraction utilities for MCP protocol
- ping
- Core MCP protocol types and error handling MCP Ping Protocol Types
- prelude
- HTTP MCP Server Prelude
- prompts
- Core MCP protocol types and error handling MCP Prompts Protocol Types
- protocol
- MCP Protocol Version Detection and Features
- resources
- Core MCP protocol types and error handling MCP Resources Protocol Types
- roots
- Core MCP protocol types and error handling MCP Roots Protocol Types
- sampling
- Core MCP protocol types and error handling MCP Sampling Protocol Types
- schema
- Core MCP protocol types and error handling 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
- Core MCP protocol types and error handling MCP Tools Protocol Types
- traits
- Core MCP protocol types and error handling Traits for JSON-RPC types as per MCP specification (2025-06-18)
- version
- Core MCP protocol types and error handling MCP Protocol Version Support
Macros§
- impl_
serde_ extractor - Core MCP protocol types and error handling Macro to implement SerdeParamExtractor for any Params type that implements Deserialize
Structs§
- Annotations
- Core MCP protocol types and error handling Generic annotations structure (matches TypeScript Annotations) Used across all MCP types that support client annotations
- Blob
Resource Contents - Core MCP protocol types and error handling Binary resource contents (matches TypeScript BlobResourceContents exactly)
- Call
Tool Request - Core MCP protocol types and error handling Complete tools/call request (matches TypeScript CallToolRequest interface)
- Call
Tool Result - Core MCP protocol types and error handling Result for tools/call (per MCP spec)
- Cancelled
Notification - Core MCP protocol types and error handling Method: “notifications/cancelled”
- Client
Capabilities - Core MCP protocol types and error handling Capabilities that a client may support
- Elicit
Create Params - Core MCP protocol types and error handling Parameters for elicitation/create request (per MCP spec)
- Elicit
Create Request - Core MCP protocol types and error handling Complete elicitation/create request (matches TypeScript ElicitRequest interface)
- Elicit
Result - Core MCP protocol types and error handling The client’s response to an elicitation request (per MCP spec)
- Elicitation
Builder - Core MCP protocol types and error handling Builder for creating common elicitation patterns
- Elicitation
Schema - Core MCP protocol types and error handling Restricted schema for elicitation (only primitive types, no nesting) - per MCP spec
- Empty
Params - Core MCP protocol types and error handling
- Empty
Result - Core MCP protocol types and error handling Empty result for successful operations (per MCP spec)
- GetPrompt
Request - Core MCP protocol types and error handling Complete prompts/get request (matches TypeScript GetPromptRequest interface)
- GetPrompt
Result - Core MCP protocol types and error handling Result for prompts/get (per MCP spec)
- Implementation
- Core MCP protocol types and error handling Describes the name and version of an MCP implementation
- Initialize
Request - Core MCP protocol types and error handling Parameters for initialize request
- Initialize
Result - Core MCP protocol types and error handling Result payload for initialize (per MCP spec)
- Initialized
Notification - Core MCP protocol types and error handling Method: “notifications/initialized”
- Json
RpcDispatcher - JSON-RPC 2.0 dispatcher and handler trait for protocol operations JSON-RPC method dispatcher with specific error type
- Json
RpcError - Core MCP protocol types and error handling JSON-RPC 2.0 error object
- Json
RpcNotification - Core MCP protocol types and error handling A JSON-RPC 2.0 notification (no response expected)
- Json
RpcRequest - Core MCP protocol types and error handling A standard JSON-RPC 2.0 request
- Json
RpcResponse - Core MCP protocol types and error handling A standard JSON-RPC 2.0 response
- List
Prompts Request - Core MCP protocol types and error handling Complete prompts/list request (matches TypeScript ListPromptsRequest interface)
- List
Prompts Result - Core MCP protocol types and error handling Result for prompts/list (per MCP spec)
- List
Resources Request - Core MCP protocol types and error handling Complete resources/list request (matches TypeScript ListResourcesRequest interface)
- List
Resources Result - Core MCP protocol types and error handling Result for resources/list (per MCP spec)
- List
Tools Request - Core MCP protocol types and error handling Complete tools/list request (matches TypeScript ListToolsRequest interface)
- List
Tools Result - Core MCP protocol types and error handling Result for tools/list (per MCP spec) - extends PaginatedResult
- Logging
Message Notification - Core MCP protocol types and error handling Method: “notifications/message”
- Logging
Message Notification Params - Core MCP protocol types and error handling
- Meta
- Core MCP protocol types and error handling Structured _meta field for MCP 2025-06-18
- Meta
Cursor - Core MCP protocol types and error handling Cursor for pagination support
- Notification
- Core MCP protocol types and error handling Base notification structure following MCP TypeScript specification
- Notification
Params - Core MCP protocol types and error handling Base notification parameters that can include _meta
- Paginated
Response - Core MCP protocol types and error handling Helper for pagination responses
- Ping
Request - Core MCP protocol types and error handling Request for ping (per MCP spec)
- Progress
Notification - Core MCP protocol types and error handling Method: “notifications/progress”
- Progress
Notification Params - Core MCP protocol types and error handling
- Progress
Response - Core MCP protocol types and error handling Helper for progress responses
- Progress
Token - Core MCP protocol types and error handling Progress token for tracking long-running operations
- Prompt
- Core MCP protocol types and error handling A prompt descriptor (matches TypeScript Prompt interface exactly)
- Prompt
Argument - Core MCP protocol types and error handling Argument definition for prompts (extends BaseMetadata per MCP spec)
- Prompt
List Changed Notification - Core MCP protocol types and error handling Method: “notifications/prompts/listChanged” (per MCP spec)
- Prompt
Message - Core MCP protocol types and error handling Message content for prompts (matches MCP PromptMessage interface exactly)
- Read
Resource Request - Core MCP protocol types and error handling Complete resources/read request (matches TypeScript ReadResourceRequest interface)
- Read
Resource Result - Core MCP protocol types and error handling Result for resources/read (per MCP spec)
- Request
Params - Core MCP protocol types and error handling
JSON-RPC
params
object with optional_meta
and method-specific arguments - Resource
- Core MCP protocol types and error handling A resource descriptor (matches TypeScript Resource interface) Resource extends BaseMetadata, so it includes name and title fields
- Resource
List Changed Notification - Core MCP protocol types and error handling Method: “notifications/resources/listChanged” (per MCP spec)
- Resource
Reference - Core MCP protocol types and error handling Resource reference for resource links (matches TypeScript Resource interface)
- Resource
Subscription - Core MCP protocol types and error handling Resource subscription parameters
- Resource
Updated Notification - Core MCP protocol types and error handling Method: “notifications/resources/updated”
- Resource
Updated Notification Params - Core MCP protocol types and error handling
- Result
With Meta - Core MCP protocol types and error handling A generic result wrapper that combines data with optional _meta information
- Roots
List Changed Notification - Core MCP protocol types and error handling Method: “notifications/roots/listChanged” (per MCP spec)
- Server
Capabilities - Core MCP protocol types and error handling Capabilities that a server may support
- Subscribe
Request - Core MCP protocol types and error handling Complete resources/subscribe request (per MCP spec)
- Text
Resource Contents - Core MCP protocol types and error handling Text resource contents (matches TypeScript TextResourceContents exactly)
- Tool
- Core MCP protocol types and error handling Tool definition
- Tool
List Changed Notification - Core MCP protocol types and error handling Method: “notifications/tools/listChanged” (per MCP spec)
- Tool
Schema - Core MCP protocol types and error handling JSON Schema definition for tool input/output (matches TypeScript spec exactly) Must be an object with type: “object”, properties, and required fields
- Unsubscribe
Request - Core MCP protocol types and error handling Complete resources/unsubscribe request (per MCP spec)
Enums§
- Content
Block - Core MCP protocol types and error handling Content block union type matching MCP 2025-06-18 specification exactly
- Elicit
Action - Core MCP protocol types and error handling User action in response to elicitation
- Http
McpError - HTTP MCP specific errors
- Json
RpcMessage - Core MCP protocol types and error handling Unified JSON-RPC message type
- Json
Schema - Core MCP protocol types and error handling A JSON Schema definition
- Legacy
Request Params - Core MCP protocol types and error handling Parameters for a JSON-RPC request
- McpError
- Core MCP protocol types and error handling MCP-specific errors
- McpVersion
- Core MCP protocol types and error handling Supported MCP protocol versions
- Primitive
Schema Definition - Core MCP protocol types and error handling Restricted schema definitions that only allow primitive types without nested objects or arrays (per MCP spec).
- Request
Id - Core MCP protocol types and error handling A uniquely identifying ID for a JSON-RPC request. Can be a string or a number, but never null.
- Resource
Content - Core MCP protocol types and error handling Union type for resource contents (matches TypeScript union)
- Resource
Contents - Core MCP protocol types and error handling Resource contents union type (matches TypeScript TextResourceContents | BlobResourceContents)
- Response
Result - Core MCP protocol types and error handling Result data for a JSON-RPC response
- String
Format - Core MCP protocol types and error handling String format constraints
Constants§
- CURRENT_
VERSION - Core MCP protocol types and error handling The current MCP protocol version implemented by this crate
- MCP_
VERSION - Core MCP protocol types and error handling The MCP protocol version implemented by this crate
Traits§
- HasData
- Core MCP protocol types and error handling
- HasData
Param - Core MCP protocol types and error handling
- HasMeta
- Core MCP protocol types and error handling
- HasMeta
Param - Core MCP protocol types and error handling
- HasProgress
Token Param - Core MCP protocol types and error handling
- Json
RpcHandler - JSON-RPC 2.0 dispatcher and handler trait for protocol operations Trait for handling JSON-RPC method calls
- Json
RpcNotification Trait - Core MCP protocol types and error handling
- Json
RpcRequest Trait - Core MCP protocol types and error handling
- Json
RpcResponse Trait - Core MCP protocol types and error handling
- Params
- Core MCP protocol types and error handling
- RpcResult
- Core MCP protocol types and error handling
- With
Meta - Core MCP protocol types and error handling Trait for types that can include _meta fields
Type Aliases§
- McpResult
- Core MCP protocol types and error handling Common result type for MCP operations
- Result
- Result type for HTTP MCP operations
- Tool
Result - Core MCP protocol types and error handling Tool result type - an alias for ContentBlock to maintain backward compatibility while ensuring MCP 2025-06-18 specification compliance