turul_mcp_aws_lambda/lib.rs
1//! AWS Lambda integration for turul-mcp-framework
2//!
3//! This crate provides seamless integration between the turul-mcp-framework and AWS Lambda,
4//! enabling serverless deployment of MCP servers with proper session management, CORS handling,
5//! and SSE streaming support.
6//!
7//! ## Architecture
8//!
9//! The crate bridges the gap between Lambda's HTTP execution model and the framework's
10//! hyper-based architecture through:
11//!
12//! - **Type Conversion**: Clean conversion between `lambda_http` and `hyper` types
13//! - **Handler Registration**: Direct tool registration with `JsonRpcDispatcher`
14//! - **Session Management**: DynamoDB-backed session persistence across invocations
15//! - **CORS Support**: Proper CORS header injection for browser clients
16//! - **SSE Streaming**: Server-Sent Events adaptation through Lambda's streaming response
17//!
18//! ## Quick Start
19//!
20//! ```rust,no_run
21//! use turul_mcp_aws_lambda::LambdaMcpServerBuilder;
22//! use turul_mcp_derive::McpTool;
23//! use turul_mcp_server::{McpResult, SessionContext};
24//! use lambda_http::{run_with_streaming_response, service_fn, Error};
25//!
26//! #[derive(McpTool, Clone, Default)]
27//! #[tool(name = "example", description = "Example tool")]
28//! struct ExampleTool {
29//! #[param(description = "Example parameter")]
30//! value: String,
31//! }
32//!
33//! impl ExampleTool {
34//! async fn execute(&self, _session: Option<SessionContext>) -> McpResult<String> {
35//! Ok(format!("Got: {}", self.value))
36//! }
37//! }
38//!
39//! #[tokio::main]
40//! async fn main() -> Result<(), Error> {
41//! let server = LambdaMcpServerBuilder::new()
42//! .tool(ExampleTool::default())
43//! .cors_allow_all_origins()
44//! .build()
45//! .await?;
46//!
47//! let handler = server.handler().await?;
48//!
49//! run_with_streaming_response(service_fn(move |req| {
50//! let handler = handler.clone();
51//! async move {
52//! handler.handle(req).await.map_err(|e| Box::new(e) as Box<dyn std::error::Error + Send + Sync>)
53//! }
54//! })).await
55//! }
56//! ```
57
58pub mod adapter;
59pub mod builder;
60pub mod error;
61pub mod handler;
62pub mod prelude;
63pub mod server;
64
65#[cfg(feature = "cors")]
66pub mod cors;
67
68#[cfg(feature = "sse")]
69pub mod streaming;
70
71// Re-exports for convenience
72/// Builder for creating Lambda MCP servers with fluent configuration API
73pub use builder::LambdaMcpServerBuilder;
74/// Lambda-specific error types and result aliases
75pub use error::{LambdaError, Result};
76/// Lambda request handler with session management and protocol conversion
77pub use handler::LambdaMcpHandler;
78/// Core Lambda MCP server implementation with DynamoDB integration
79pub use server::LambdaMcpServer;
80
81#[cfg(feature = "cors")]
82pub use cors::CorsConfig;