Expand description
AWS Lambda integration for turul-mcp-framework
This crate provides seamless integration between the turul-mcp-framework and AWS Lambda, enabling serverless deployment of MCP servers with proper session management, CORS handling, and SSE streaming support.
§Architecture
The crate bridges the gap between Lambda’s HTTP execution model and the framework’s hyper-based architecture through:
- Type Conversion: Clean conversion between
lambda_httpandhypertypes - Handler Registration: Direct tool registration with
JsonRpcDispatcher - Session Management: DynamoDB-backed session persistence across invocations
- CORS Support: Proper CORS header injection for browser clients
- SSE Streaming: Server-Sent Events adaptation through Lambda’s streaming response
§Quick Start
use turul_mcp_aws_lambda::LambdaMcpServerBuilder;
use turul_mcp_derive::McpTool;
use turul_mcp_server::{McpResult, SessionContext};
#[derive(McpTool, Clone, Default)]
#[tool(name = "example", description = "Example tool")]
struct ExampleTool {
#[param(description = "Example parameter")]
value: String,
}
impl ExampleTool {
async fn execute(&self, _session: Option<SessionContext>) -> McpResult<String> {
Ok(format!("Got: {}", self.value))
}
}
#[tokio::main]
async fn main() -> Result<(), lambda_http::Error> {
let server = LambdaMcpServerBuilder::new()
.tool(ExampleTool::default())
.cors_allow_all_origins()
.build()
.await?;
let handler = server.handler().await?;
// run_streaming handles API Gateway completion invocations gracefully
turul_mcp_aws_lambda::run_streaming(handler).await
}§Streaming Entry Points
Two entry points replace lambda_http::run_with_streaming_response():
run_streaming()— standard path: pass aLambdaMcpHandlerdirectlyrun_streaming_with()— custom dispatch: provide your own closure for pre-dispatch logic (e.g.,.well-knownrouting) while still getting completion-invocation handling for free
Re-exports§
pub use builder::LambdaMcpServerBuilder;pub use error::LambdaError;pub use error::Result;pub use handler::LambdaMcpHandler;pub use server::LambdaMcpServer;pub use cors::CorsConfig;
Modules§
- adapter
- HTTP type conversion utilities for Lambda MCP requests
- builder
- High-level builder API for Lambda MCP servers
- cors
- CORS (Cross-Origin Resource Sharing) support for Lambda MCP servers
- error
- Error handling for Lambda MCP integration
- handler
- Lambda MCP handler that delegates to SessionMcpHandler
- prelude
- AWS Lambda MCP Server Prelude
- server
- Lambda MCP Server Implementation
- streaming
- SSE (Server-Sent Events) streaming adaptation for AWS Lambda
Functions§
- run_
streaming - Run the Lambda MCP handler with streaming response support.
- run_
streaming_ with - Run a custom dispatch function with streaming response support.