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 client;
37pub mod config;
38pub mod proxy_handler;
39pub mod server;
40pub mod session_manager;
41
42// Re-export main types
43pub use proxy_handler::{ProxyHandler, ToolFilter};
44pub use server::{McpServiceConfig, run_stream_server, run_stream_server_from_config};
45pub use session_manager::ProxyAwareSessionManager;
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, ServiceExt,
54 model::{ClientCapabilities, ClientInfo, ServerInfo},
55 service::{Peer, RunningService},
56};
57
58// Re-export transport types for Streamable HTTP protocol (rmcp 0.12)
59pub use rmcp::transport::{
60 StreamableHttpServerConfig,
61 child_process::TokioChildProcess,
62 stdio, // stdio transport for CLI mode
63 streamable_http_client::StreamableHttpClientTransport,
64 streamable_http_client::StreamableHttpClientTransportConfig,
65};
66
67// Re-export server-side Streamable HTTP types
68pub use rmcp::transport::streamable_http_server::{
69 StreamableHttpService, session::local::LocalSessionManager,
70};