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.3"
turul-mcp-server = "0.3"§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 routes::RouteBody;pub use routes::RouteHandler;pub use routes::RouteRegistry;pub use routes::RouteValidationError;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-11-25 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
- icons
- Core MCP protocol types and error handling MCP Icon Types
- 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-11-25
- 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-11-25
- middleware
- Middleware system for MCP servers
- 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
- routes
- Route registry for custom HTTP paths (e.g.,
.well-knownendpoints) - 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-11-25 Resumability
- streamable_
http - Streamable HTTP Transport for MCP 2025-11-25
- tasks
- Core MCP protocol types and error handling MCP Tasks Protocol Types
- 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-11-25)
- 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 Annotations for resources, prompts, and tools (matches TypeScript Annotations per MCP 2025-11-25). See MCP spec
- 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)
- Cancel
Task Params - Core MCP protocol types and error handling Parameters for tasks/cancel request
- Cancel
Task Request - Core MCP protocol types and error handling Complete tasks/cancel request
- Cancel
Task Result - Core MCP protocol types and error handling
Result for tasks/cancel — flattens Task fields per TS
Result & Task - 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 (per MCP 2025-11-25)
- Create
Task Result - Core MCP protocol types and error handling Returned when a task-augmented request is accepted (instead of the operation’s direct result).
- 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
Complete Notification - Core MCP protocol types and error handling Method: “notifications/elicitation/complete” (per MCP 2025-11-25)
- 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)
- GetTask
Params - Core MCP protocol types and error handling Parameters for tasks/get request
- GetTask
Payload Params - Core MCP protocol types and error handling Parameters for tasks/result request (retrieves the original operation’s result)
- GetTask
Payload Request - Core MCP protocol types and error handling Complete tasks/result request
- GetTask
Request - Core MCP protocol types and error handling Complete tasks/get request
- GetTask
Result - Core MCP protocol types and error handling
Result for tasks/get — flattens Task fields per TS
Result & Task - Icon
- Core MCP protocol types and error handling Icon for tools, resources, prompts, and implementations. Icons are display hints — most implementations do not need icons. See 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
Tasks Params - Core MCP protocol types and error handling Parameters for tasks/list request
- List
Tasks Request - Core MCP protocol types and error handling Complete tasks/list request
- List
Tasks Result - Core MCP protocol types and error handling Result for tasks/list (extends PaginatedResult)
- 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-11-25
- 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/list_changed” (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
paramsobject with optional_metaand 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/list_changed” (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/list_changed” (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)
- Task
- Core MCP protocol types and error handling Core task descriptor per MCP 2025-11-25. See MCP spec
- Task
Metadata - Core MCP protocol types and error handling
Task metadata for task-augmented requests.
Added to
CallToolParams,CreateMessageParams,ElicitCreateParamsto indicate that the operation should create a task. - Task
Status Notification - Core MCP protocol types and error handling Method: “notifications/tasks/status” (per MCP 2025-11-25)
- Tasks
Cancel Capabilities - Core MCP protocol types and error handling Signals support for tasks/cancel — presence means supported, extensible via extra
- Tasks
Capabilities - Core MCP protocol types and error handling Capabilities for tasks (per MCP 2025-11-25)
- Tasks
List Capabilities - Core MCP protocol types and error handling Signals support for tasks/list — presence means supported, extensible via extra
- Tasks
Request Capabilities - Core MCP protocol types and error handling Describes which request types support task augmentation
- Tasks
Tool Call Capabilities - Core MCP protocol types and error handling Signals support for task-augmented tools/call — presence means supported
- Tasks
Tool Capabilities - Core MCP protocol types and error handling Tool-level task capabilities
- 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
Execution - Core MCP protocol types and error handling Execution configuration for a tool (per MCP 2025-11-25)
- Tool
List Changed Notification - Core MCP protocol types and error handling Method: “notifications/tools/list_changed” (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-11-25 specification exactly
- Elicit
Action - Core MCP protocol types and error handling User action in response to elicitation
- Http
McpError - HTTP MCP specific errors
- Icon
Theme - Core MCP protocol types and error handling Theme preference for an icon (light or dark mode). See MCP spec
- 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).
- Progress
Token Value - Core MCP protocol types and error handling Progress token value — can be a string or a number per MCP 2025-11-25. See 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
- Task
Status - Core MCP protocol types and error handling Task status enum per MCP 2025-11-25. See MCP spec
- Task
Support - Core MCP protocol types and error handling Whether a tool supports long-running task execution (per MCP 2025-11-25)
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-11-25 specification compliance