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,
) -> 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, ) -> Self
Create with custom middleware stack (for testing and examples)
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 moreAuto Trait Implementations§
impl Freeze for LambdaMcpHandler
impl !RefUnwindSafe for LambdaMcpHandler
impl Send for LambdaMcpHandler
impl Sync for LambdaMcpHandler
impl Unpin for LambdaMcpHandler
impl !UnwindSafe for LambdaMcpHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more