turul-http-mcp-server
HTTP transport layer for Model Context Protocol (MCP) servers with full MCP 2025-06-18 Streamable HTTP compliance and SSE support.
Overview
turul-http-mcp-server
provides the HTTP transport layer for the turul-mcp-framework, implementing MCP Streamable HTTP with Server-Sent Events (SSE) for real-time notifications and session resumability.
Features
- ✅ MCP 2025-06-18 Streamable HTTP - Full protocol compliance with SSE streaming
- ✅ Session Management - UUID v7 session IDs with automatic cleanup
- ✅ SSE Resumability - Last-Event-ID support with event replay
- ✅ CORS Support - Browser client compatibility with configurable origins
- ✅ Protocol Version Detection - Automatic feature flags based on client capabilities
- ✅ Pluggable Storage - InMemory, SQLite, PostgreSQL, DynamoDB session backends
- ✅ Performance Optimized - Connection pooling, streaming responses, efficient JSON-RPC dispatch
Quick Start
Add this to your Cargo.toml
:
[]
= "0.1.1"
= "0.1.1"
= "0.1.1"
Basic HTTP MCP Server
use ;
use McpServer;
use mcp_tool;
use McpResult;
use SocketAddr;
async
async
Streamable HTTP Architecture
Protocol Flow
The HTTP MCP server implements the MCP 2025-06-18 Streamable HTTP specification:
┌─────────────────────────────────────────────────┐
│ MCP Client │
├─────────────────────────────────────────────────┤
│ POST /mcp + Accept: application/json │ ← JSON-RPC requests
│ GET /mcp + Accept: text/event-stream │ ← SSE notifications
├─────────────────────────────────────────────────┤
│ turul-http-mcp-server │
│ ├─ SessionMcpHandler │ ← Session management
│ ├─ StreamManager │ ← SSE event streaming
│ ├─ NotificationBroadcaster │ ← Real-time notifications
│ └─ JsonRpcDispatcher │ ← JSON-RPC routing
├─────────────────────────────────────────────────┤
│ turul-mcp-server │ ← Core framework
└─────────────────────────────────────────────────┘
Session Management
Sessions are managed with UUID v7 for temporal ordering:
use ;
use SqliteSessionStorage;
use Arc;
let storage = new;
let server = new
.bind_address
.session_storage // Persistent session storage
.enable_sse
.build
.await?;
SSE Event Streaming
Real-time notifications are delivered via Server-Sent Events:
use mcp_tool;
use ;
async
Advanced Configuration
Custom Server Builder
use ;
use PostgreSqlSessionStorage;
let cors = new
.allow_origins
.allow_credentials;
let storage = new;
let server = new
.bind_address
.mcp_path
.session_storage
.cors
.max_body_size // 2MB
.enable_sse
.build
.await?;
Protocol Version Detection
The server automatically detects client capabilities:
// Client sends MCP-Protocol-Version header
// Server responds with appropriate feature set:
// V2024_11_05: Basic MCP without streamable HTTP
// V2025_03_26: Streamable HTTP support
// V2025_06_18: Full feature set with _meta, cursor, progressToken
CORS Configuration
Browser Client Support
use ;
// Allow all origins (development)
let server = new
.enable_cors // Uses permissive defaults
.build
.await?;
// Custom CORS configuration (production)
let cors = new
.allow_origins
.allow_methods
.allow_headers
.allow_credentials;
let server = new
.cors
.build
.await?;
Session Storage Backends
InMemory (Development)
use HttpMcpServerBuilder;
use InMemorySessionStorage;
let server = new
.session_storage // Default
.build
.await?;
SQLite (Single Instance)
use SqliteSessionStorage;
let storage = new;
let server = new
.session_storage
.build
.await?;
PostgreSQL (Multi-Instance)
use PostgreSqlSessionStorage;
let storage = new;
let server = new
.session_storage
.build
.await?;
DynamoDB (Serverless)
use DynamoDbSessionStorage;
let storage = new;
let server = new
.session_storage
.build
.await?;
Real-time Notifications
SSE Event Types
The server supports all MCP notification types via SSE:
// Progress notifications
session.notify_progress.await?;
// Resource update notifications
session.notify_resource_updated.await?;
// Prompt update notifications
session.notify_prompt_updated.await?;
// Log notifications
session.notify_log.await?;
SSE Resumability
Clients can resume from any event using Last-Event-ID:
# Initial connection
# Resume from specific event
Testing
MCP Inspector Integration
Test your server with MCP Inspector:
# Start server
# Connect MCP Inspector
# URL: http://localhost:3000/mcp
# Enable SSE notifications for real-time updates
Manual Testing
# 1. Initialize session
# 2. Call tool with session
# 3. Open SSE stream for notifications
Performance
Optimized Architecture
- Connection Pooling: Database connections shared across requests
- Streaming Responses: Efficient SSE event delivery without buffering
- JSON-RPC Dispatch: Fast method routing with compile-time registration
- Session Cleanup: Automatic cleanup every 60 seconds with 30-minute expiry
Monitoring
use ;
// Server statistics
let stats = server.stats.await;
println!;
println!;
// Stream statistics
let stream_stats = server.stream_stats.await;
println!;
println!;
Error Handling
HTTP Error Responses
The server provides proper HTTP error responses with MCP-compliant JSON-RPC errors:
use ;
// Tool implementation with error handling
async
Graceful Degradation
// Session operations fail gracefully
if let Err = session.set_typed_state.await
Examples
Complete Production Server
use ;
use McpServer;
use PostgreSqlSessionStorage;
use mcp_tool;
use Arc;
async
async
Feature Flags
[]
= { = "0.1.1", = ["sse"] }
default
=["sse"]
- Includes SSE support by defaultsse
- Server-Sent Events streaming for real-time notifications
Compatibility
MCP Protocol Versions
- 2024-11-05: Basic MCP without streamable HTTP
- 2025-03-26: Streamable HTTP with SSE support
- 2025-06-18: Full feature set with meta fields and enhanced capabilities
HTTP Clients
- MCP Inspector: Full compatibility with browser-based testing
- curl: Command-line testing and integration
- JavaScript/TypeScript: Browser and Node.js client support
- Python: Using
requests
library with SSE support
License
Licensed under the MIT License. See LICENSE for details.