mcp_streamable_proxy/
lib.rs

1//! MCP Streamable HTTP Proxy Module
2//!
3//! This module provides a proxy implementation for MCP (Model Context Protocol)
4//! using Streamable HTTP transport with stateful session management.
5//!
6//! # Features
7//!
8//! - **Streamable HTTP Support**: Uses rmcp 0.12 with enhanced Streamable HTTP transport
9//! - **Stateful Sessions**: Custom SessionManager with backend version tracking
10//! - **Hot Swap**: Supports backend connection replacement without downtime
11//! - **Version Control**: Automatically invalidates sessions when backend reconnects
12//! - **High-level Client API**: Simple connection interface hiding transport details
13//!
14//! # Architecture
15//!
16//! ```text
17//! Client → Streamable HTTP → ProxyAwareSessionManager → ProxyHandler → Backend MCP Service
18//!                                    ↓
19//!                            Version Tracking
20//!                            (DashMap<SessionId, BackendVersion>)
21//! ```
22//!
23//! # Example
24//!
25//! ```rust,ignore
26//! use mcp_streamable_proxy::{StreamClientConnection, McpClientConfig};
27//!
28//! // Connect to an MCP server
29//! let config = McpClientConfig::new("http://localhost:8080/mcp");
30//! let conn = StreamClientConnection::connect(config).await?;
31//!
32//! // List available tools
33//! let tools = conn.list_tools().await?;
34//! ```
35
36pub mod proxy_handler;
37pub mod session_manager;
38pub mod server;
39pub mod config;
40pub mod client;
41
42// Re-export main types
43pub use proxy_handler::{ProxyHandler, ToolFilter};
44pub use session_manager::ProxyAwareSessionManager;
45pub use server::{run_stream_server, run_stream_server_from_config, McpServiceConfig};
46
47// Re-export client connection types
48pub use client::{StreamClientConnection, ToolInfo};
49pub use mcp_common::McpClientConfig;
50
51// Re-export commonly used rmcp types
52pub use rmcp::{
53    RoleClient, RoleServer, ServerHandler,
54    model::{ServerInfo, ClientInfo, ClientCapabilities},
55    service::{RunningService, Peer},
56    ServiceExt,
57};
58
59// Re-export transport types for Streamable HTTP protocol (rmcp 0.12)
60pub use rmcp::transport::{
61    child_process::TokioChildProcess,
62    streamable_http_client::StreamableHttpClientTransport,
63    streamable_http_client::StreamableHttpClientTransportConfig,
64    StreamableHttpServerConfig,
65    stdio,  // stdio transport for CLI mode
66};
67
68// Re-export server-side Streamable HTTP types
69pub use rmcp::transport::streamable_http_server::{
70    StreamableHttpService,
71    session::local::LocalSessionManager,
72};