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 detector;
39pub mod proxy_handler;
40pub mod server;
41pub mod server_builder;
42pub mod session_manager;
43
44// Re-export main types
45pub use proxy_handler::{ProxyHandler, ToolFilter};
46pub use server::{McpServiceConfig, run_stream_server, run_stream_server_from_config};
47pub use session_manager::ProxyAwareSessionManager;
48
49// Re-export protocol detection function
50pub use detector::is_streamable_http;
51
52// Re-export server builder API
53pub use server_builder::{BackendConfig, StreamServerBuilder, StreamServerConfig};
54
55// Re-export client connection types
56pub use client::{StreamClientConnection, ToolInfo};
57pub use mcp_common::McpClientConfig;
58
59// Re-export commonly used rmcp types
60pub use rmcp::{
61 RoleClient, RoleServer, ServerHandler, ServiceExt,
62 model::{ClientCapabilities, ClientInfo, Implementation, ServerInfo},
63 service::{Peer, RunningService},
64};
65
66// Re-export transport types for Streamable HTTP protocol (rmcp 0.12)
67pub use rmcp::transport::{
68 StreamableHttpServerConfig,
69 child_process::TokioChildProcess,
70 stdio, // stdio transport for CLI mode
71 streamable_http_client::StreamableHttpClientTransport,
72 streamable_http_client::StreamableHttpClientTransportConfig,
73};
74
75// Re-export server-side Streamable HTTP types
76pub use rmcp::transport::streamable_http_server::{
77 StreamableHttpService, session::local::LocalSessionManager,
78};