mcp_stdio_proxy/proxy/mod.rs
1//! Proxy module - re-exports handler types from proxy libraries
2//!
3//! This module provides a unified interface for proxy handlers by re-exporting
4//! types from mcp-sse-proxy, mcp-streamable-proxy, and mcp-common libraries.
5
6// Re-export SseHandler as ProxyHandler for backward compatibility
7// SseHandler is used because it's based on rmcp 0.10 which supports both
8// SSE server mode and CLI stdio mode used in the main project
9pub use mcp_sse_proxy::SseHandler as ProxyHandler;
10
11// Re-export StreamProxyHandler with an alias to distinguish from SSE ProxyHandler
12// Both mcp-sse-proxy and mcp-streamable-proxy export ProxyHandler, so we use an alias
13pub use mcp_streamable_proxy::ProxyHandler as StreamProxyHandler;
14
15// Re-export ToolFilter from mcp-common
16pub use mcp_common::ToolFilter;
17
18// Re-export client connection types for high-level API (each from its own library)
19pub use mcp_sse_proxy::{McpClientConfig, SseClientConnection};
20pub use mcp_streamable_proxy::StreamClientConnection;
21
22// Re-export Builder APIs for server creation
23pub use mcp_sse_proxy::server_builder::{BackendConfig as SseBackendConfig, SseServerBuilder};
24pub use mcp_streamable_proxy::server_builder::{
25 BackendConfig as StreamBackendConfig, StreamServerBuilder,
26};
27
28/// Unified handler enum that can hold either SSE or Stream handler
29///
30/// This allows ProxyHandlerManager to store handlers of either type
31/// while providing a common interface for status checks.
32#[derive(Clone, Debug)]
33pub enum McpHandler {
34 /// SSE protocol handler (from mcp-sse-proxy)
35 Sse(Box<ProxyHandler>),
36 /// Streamable HTTP protocol handler (from mcp-streamable-proxy)
37 Stream(Box<StreamProxyHandler>),
38}
39
40impl McpHandler {
41 /// Check if the underlying MCP server is ready
42 pub async fn is_mcp_server_ready(&self) -> bool {
43 match self {
44 McpHandler::Sse(h) => h.is_mcp_server_ready().await,
45 McpHandler::Stream(h) => h.is_mcp_server_ready().await,
46 }
47 }
48
49 /// Check if the backend connection is terminated
50 pub async fn is_terminated_async(&self) -> bool {
51 match self {
52 McpHandler::Sse(h) => h.is_terminated_async().await,
53 McpHandler::Stream(h) => h.is_terminated_async().await,
54 }
55 }
56}
57
58impl From<ProxyHandler> for McpHandler {
59 fn from(handler: ProxyHandler) -> Self {
60 McpHandler::Sse(Box::new(handler))
61 }
62}
63
64impl From<StreamProxyHandler> for McpHandler {
65 fn from(handler: StreamProxyHandler) -> Self {
66 McpHandler::Stream(Box::new(handler))
67 }
68}