Crate turul_mcp_aws_lambda

Crate turul_mcp_aws_lambda 

Source
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_http and hyper types
  • 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};
use lambda_http::{run_with_streaming_response, service_fn, Error};

#[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<(), Error> {
    let server = LambdaMcpServerBuilder::new()
        .tool(ExampleTool::default())
        .cors_allow_all_origins()
        .build()
        .await?;

    let handler = server.handler().await?;

    run_with_streaming_response(service_fn(move |req| {
        let handler = handler.clone();
        async move {
            handler.handle(req).await.map_err(|e| Box::new(e) as Box<dyn std::error::Error + Send + Sync>)
        }
    })).await
}

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