Skip to main content

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 with Streamable HTTP transport
9//! - **Stateful Sessions**: Custom SessionManager with backend version tracking
10//! - **Per-session URL backends**: each upstream session connects its own backend on `initialize`
11//! - **Shared stdio backends**: one child process shared across sessions
12//! - **Hot Swap**: Supports backend connection replacement (shared isolation)
13//!
14//! # Architecture
15//!
16//! ```text
17//! Client → Streamable HTTP → ProxyAwareSessionManager → ProxyHandler → Backend MCP Service
18//!   URL (per-session): each session opens its own backend (connect on initialize)
19//!   Stdio (shared): one backend, clones share Arcs + notification fan-out registry
20//! ```
21//!
22//! # Example
23//!
24//! ```rust,ignore
25//! use mcp_streamable_proxy::{StreamClientConnection, McpClientConfig};
26//!
27//! // Connect to an MCP server
28//! let config = McpClientConfig::new("http://localhost:8080/mcp");
29//! let conn = StreamClientConnection::connect(config).await?;
30//!
31//! // List available tools
32//! let tools = conn.list_tools().await?;
33//! ```
34
35pub mod backend_client;
36pub mod backend_connector;
37pub mod client;
38pub mod config;
39pub mod detector;
40pub mod proxy_handler;
41pub mod server;
42pub mod server_builder;
43pub mod session_manager;
44
45// Re-export main types
46pub use backend_client::{
47    BackendNotificationBridge, NotifyTarget, ProgressRouteGuard, UpstreamPeerRegistry,
48    UpstreamPeerSlot,
49};
50pub use backend_connector::{
51    BackendConnector, BackendIsolation, StdioBackendConnector, UrlBackendConnector,
52};
53pub use mcp_common::McpServiceConfig;
54pub use proxy_handler::{BackendRunningService, ProxyHandler, ToolFilter};
55pub use server::{run_stream_server, run_stream_server_from_config};
56pub use session_manager::ProxyAwareSessionManager;
57
58// Re-export protocol detection function
59pub use detector::{is_streamable_http, is_streamable_http_with_headers};
60
61// Re-export server builder API
62pub use server_builder::{BackendConfig, StreamServerBuilder, StreamServerConfig};
63
64// Re-export client connection types
65pub use client::{StreamClientConnection, ToolInfo};
66pub use mcp_common::McpClientConfig;
67
68// Re-export commonly used rmcp types
69pub use rmcp::{
70    RoleClient, RoleServer, ServerHandler, ServiceExt,
71    model::{ClientCapabilities, ClientInfo, Implementation, ServerInfo},
72    service::{Peer, RunningService},
73};
74
75// Re-export transport types for Streamable HTTP protocol
76pub use rmcp::transport::{
77    StreamableHttpServerConfig,
78    child_process::TokioChildProcess,
79    stdio,
80    streamable_http_client::StreamableHttpClientTransport,
81    streamable_http_client::StreamableHttpClientTransportConfig,
82};
83
84// Re-export server-side Streamable HTTP types
85pub use rmcp::transport::streamable_http_server::{
86    StreamableHttpService, session::local::LocalSessionManager,
87};