pub struct LambdaMcpHandler { /* private fields */ }Expand description
Main handler for Lambda MCP requests
This handler processes MCP requests in Lambda by delegating to SessionMcpHandler, eliminating 600+ lines of duplicate business logic code.
Features:
- Type conversion between lambda_http and hyper
- Delegation to SessionMcpHandler for all business logic
- CORS support for browser clients
- SSE validation to prevent silent failures
Implementations§
Source§impl LambdaMcpHandler
impl LambdaMcpHandler
Sourcepub fn new(
dispatcher: JsonRpcDispatcher<McpError>,
session_storage: Arc<BoxedSessionStorage>,
stream_manager: Arc<StreamManager>,
config: ServerConfig,
stream_config: StreamConfig,
_implementation: Implementation,
capabilities: ServerCapabilities,
sse_enabled: bool,
cors_config: Option<CorsConfig>,
) -> Self
pub fn new( dispatcher: JsonRpcDispatcher<McpError>, session_storage: Arc<BoxedSessionStorage>, stream_manager: Arc<StreamManager>, config: ServerConfig, stream_config: StreamConfig, _implementation: Implementation, capabilities: ServerCapabilities, sse_enabled: bool, cors_config: Option<CorsConfig>, ) -> Self
Create a new Lambda MCP handler with the framework components
Create with shared stream manager (for advanced use cases)
Sourcepub fn with_middleware(
config: ServerConfig,
dispatcher: Arc<JsonRpcDispatcher<McpError>>,
session_storage: Arc<BoxedSessionStorage>,
stream_manager: Arc<StreamManager>,
stream_config: StreamConfig,
capabilities: ServerCapabilities,
middleware_stack: Arc<MiddlewareStack>,
sse_enabled: bool,
route_registry: Arc<RouteRegistry>,
) -> Self
pub fn with_middleware( config: ServerConfig, dispatcher: Arc<JsonRpcDispatcher<McpError>>, session_storage: Arc<BoxedSessionStorage>, stream_manager: Arc<StreamManager>, stream_config: StreamConfig, capabilities: ServerCapabilities, middleware_stack: Arc<MiddlewareStack>, sse_enabled: bool, route_registry: Arc<RouteRegistry>, ) -> Self
Create with custom middleware stack (for testing and examples)
Sourcepub fn with_middleware_and_fingerprint(
config: ServerConfig,
dispatcher: Arc<JsonRpcDispatcher<McpError>>,
session_storage: Arc<BoxedSessionStorage>,
stream_manager: Arc<StreamManager>,
stream_config: StreamConfig,
capabilities: ServerCapabilities,
middleware_stack: Arc<MiddlewareStack>,
sse_enabled: bool,
route_registry: Arc<RouteRegistry>,
tool_fingerprint: Option<String>,
) -> Self
pub fn with_middleware_and_fingerprint( config: ServerConfig, dispatcher: Arc<JsonRpcDispatcher<McpError>>, session_storage: Arc<BoxedSessionStorage>, stream_manager: Arc<StreamManager>, stream_config: StreamConfig, capabilities: ServerCapabilities, middleware_stack: Arc<MiddlewareStack>, sse_enabled: bool, route_registry: Arc<RouteRegistry>, tool_fingerprint: Option<String>, ) -> Self
Create with custom middleware stack and tool fingerprint for session versioning
Sourcepub fn with_tool_notifier(self, notifier: Arc<dyn ToolChangeNotifier>) -> Self
pub fn with_tool_notifier(self, notifier: Arc<dyn ToolChangeNotifier>) -> Self
Set the tool change notifier for restart/redeploy fingerprint mismatch notifications.
Sourcepub fn with_cors(self, cors_config: CorsConfig) -> Self
pub fn with_cors(self, cors_config: CorsConfig) -> Self
Set CORS configuration
Sourcepub fn get_stream_manager(&self) -> &Arc<StreamManager>
pub fn get_stream_manager(&self) -> &Arc<StreamManager>
Get access to the underlying stream manager for notifications
Sourcepub async fn handle(
&self,
req: LambdaRequest,
) -> Result<LambdaResponse<LambdaBody>>
pub async fn handle( &self, req: LambdaRequest, ) -> Result<LambdaResponse<LambdaBody>>
Handle a Lambda HTTP request (snapshot mode - no real-time SSE)
This method performs delegation to SessionMcpHandler for all business logic. It only handles Lambda-specific concerns: CORS and type conversion.
Note: If SSE is enabled (.sse(true)), SSE responses may not stream properly with regular Lambda runtime. For proper SSE streaming, use handle_streaming() with run_with_streaming_response().
Sourcepub async fn handle_streaming(
&self,
req: LambdaRequest,
) -> Result<Response<UnsyncBoxBody<Bytes, Error>>, Box<dyn Error + Send + Sync>>
pub async fn handle_streaming( &self, req: LambdaRequest, ) -> Result<Response<UnsyncBoxBody<Bytes, Error>>, Box<dyn Error + Send + Sync>>
Handle Lambda streaming request (real SSE streaming)
This method enables real-time SSE streaming using Lambda’s streaming response capability. It delegates all business logic to SessionMcpHandler.
Trait Implementations§
Source§impl Clone for LambdaMcpHandler
impl Clone for LambdaMcpHandler
Source§fn clone(&self) -> LambdaMcpHandler
fn clone(&self) -> LambdaMcpHandler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more