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