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 fallback;
41pub mod proxy_handler;
42pub mod server;
43pub mod server_builder;
44pub mod session_manager;
45
46// Re-export main types
47pub use backend_client::{
48    BackendNotificationBridge, NotifyTarget, ProgressRouteGuard, UpstreamPeerRegistry,
49    UpstreamPeerSlot,
50};
51pub use backend_connector::{
52    BackendConnector, BackendIsolation, StdioBackendConnector, UrlBackendConnector,
53};
54pub use mcp_common::McpServiceConfig;
55pub use proxy_handler::{BackendRunningService, ProxyHandler, ToolFilter};
56pub use server::{run_stream_server, run_stream_server_from_config};
57pub use session_manager::ProxyAwareSessionManager;
58
59// Re-export protocol detection function
60pub use detector::{is_streamable_http, is_streamable_http_with_headers};
61
62// Re-export server builder API
63pub use server_builder::{BackendConfig, StreamServerBuilder, StreamServerConfig};
64
65// Re-export client connection types
66pub use client::{StreamClientConnection, ToolInfo};
67pub use fallback::{DiscoverySnapshot, FallbackMetadata};
68pub use mcp_common::McpClientConfig;
69
70// Re-export commonly used rmcp types
71pub use rmcp::{
72    RoleClient, RoleServer, ServerHandler, ServiceExt,
73    model::{ClientCapabilities, ClientConfig, Implementation, ServerConfig},
74    service::{Peer, RunningService},
75};
76
77// Re-export transport types for Streamable HTTP protocol
78pub use rmcp::transport::{
79    StreamableHttpServerConfig, child_process::TokioChildProcess, 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};