pub struct LambdaMcpServerBuilder { /* private fields */ }Expand description
High-level builder for Lambda MCP servers
This provides a clean, fluent API for building Lambda MCP servers similar to the framework’s McpServer::builder() pattern.
§Example
use std::sync::Arc;
use turul_mcp_aws_lambda::LambdaMcpServerBuilder;
use turul_mcp_session_storage::InMemorySessionStorage;
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<(), Box<dyn std::error::Error>> {
let server = LambdaMcpServerBuilder::new()
.name("my-lambda-server")
.version("1.0.0")
.tool(ExampleTool::default())
.storage(Arc::new(InMemorySessionStorage::new()))
.cors_allow_all_origins()
.build()
.await?;
// Use with Lambda runtime...
Ok(())
}Implementations§
Source§impl LambdaMcpServerBuilder
impl LambdaMcpServerBuilder
Sourcepub fn instructions(self, instructions: impl Into<String>) -> Self
pub fn instructions(self, instructions: impl Into<String>) -> Self
Set optional instructions for clients
Sourcepub fn tool<T: McpTool + 'static>(self, tool: T) -> Self
pub fn tool<T: McpTool + 'static>(self, tool: T) -> Self
Register a tool with the server
Tools can be created using any of the framework’s 4 creation levels:
- Function macros:
#[mcp_tool] - Derive macros:
#[derive(McpTool)] - Builder pattern:
ToolBuilder::new(...).build() - Manual implementation: Custom struct implementing
McpTool
Sourcepub fn tool_fn<F, T>(self, func: F) -> Self
pub fn tool_fn<F, T>(self, func: F) -> Self
Register a function tool created with #[mcp_tool] macro
Sourcepub fn tools<T: McpTool + 'static, I: IntoIterator<Item = T>>(
self,
tools: I,
) -> Self
pub fn tools<T: McpTool + 'static, I: IntoIterator<Item = T>>( self, tools: I, ) -> Self
Register multiple tools
Sourcepub fn resource<R: McpResource + 'static>(self, resource: R) -> Self
pub fn resource<R: McpResource + 'static>(self, resource: R) -> Self
Register a resource with the server
Sourcepub fn resources<R: McpResource + 'static, I: IntoIterator<Item = R>>(
self,
resources: I,
) -> Self
pub fn resources<R: McpResource + 'static, I: IntoIterator<Item = R>>( self, resources: I, ) -> Self
Register multiple resources
Sourcepub fn prompt<P: McpPrompt + 'static>(self, prompt: P) -> Self
pub fn prompt<P: McpPrompt + 'static>(self, prompt: P) -> Self
Register a prompt with the server
Sourcepub fn prompts<P: McpPrompt + 'static, I: IntoIterator<Item = P>>(
self,
prompts: I,
) -> Self
pub fn prompts<P: McpPrompt + 'static, I: IntoIterator<Item = P>>( self, prompts: I, ) -> Self
Register multiple prompts
Sourcepub fn elicitation<E: McpElicitation + 'static>(self, elicitation: E) -> Self
pub fn elicitation<E: McpElicitation + 'static>(self, elicitation: E) -> Self
Register an elicitation provider with the server
Sourcepub fn elicitations<E: McpElicitation + 'static, I: IntoIterator<Item = E>>(
self,
elicitations: I,
) -> Self
pub fn elicitations<E: McpElicitation + 'static, I: IntoIterator<Item = E>>( self, elicitations: I, ) -> Self
Register multiple elicitation providers
Sourcepub fn sampling_provider<S: McpSampling + 'static>(self, sampling: S) -> Self
pub fn sampling_provider<S: McpSampling + 'static>(self, sampling: S) -> Self
Register a sampling provider with the server
Sourcepub fn sampling_providers<S: McpSampling + 'static, I: IntoIterator<Item = S>>(
self,
sampling: I,
) -> Self
pub fn sampling_providers<S: McpSampling + 'static, I: IntoIterator<Item = S>>( self, sampling: I, ) -> Self
Register multiple sampling providers
Sourcepub fn completion_provider<C: McpCompletion + 'static>(
self,
completion: C,
) -> Self
pub fn completion_provider<C: McpCompletion + 'static>( self, completion: C, ) -> Self
Register a completion provider with the server
Sourcepub fn completion_providers<C: McpCompletion + 'static, I: IntoIterator<Item = C>>(
self,
completions: I,
) -> Self
pub fn completion_providers<C: McpCompletion + 'static, I: IntoIterator<Item = C>>( self, completions: I, ) -> Self
Register multiple completion providers
Sourcepub fn logger<L: McpLogger + 'static>(self, logger: L) -> Self
pub fn logger<L: McpLogger + 'static>(self, logger: L) -> Self
Register a logger with the server
Sourcepub fn loggers<L: McpLogger + 'static, I: IntoIterator<Item = L>>(
self,
loggers: I,
) -> Self
pub fn loggers<L: McpLogger + 'static, I: IntoIterator<Item = L>>( self, loggers: I, ) -> Self
Register multiple loggers
Sourcepub fn root_provider<R: McpRoot + 'static>(self, root: R) -> Self
pub fn root_provider<R: McpRoot + 'static>(self, root: R) -> Self
Register a root provider with the server
Sourcepub fn root_providers<R: McpRoot + 'static, I: IntoIterator<Item = R>>(
self,
roots: I,
) -> Self
pub fn root_providers<R: McpRoot + 'static, I: IntoIterator<Item = R>>( self, roots: I, ) -> Self
Register multiple root providers
Sourcepub fn notification_provider<N: McpNotification + 'static>(
self,
notification: N,
) -> Self
pub fn notification_provider<N: McpNotification + 'static>( self, notification: N, ) -> Self
Register a notification provider with the server
Sourcepub fn notification_providers<N: McpNotification + 'static, I: IntoIterator<Item = N>>(
self,
notifications: I,
) -> Self
pub fn notification_providers<N: McpNotification + 'static, I: IntoIterator<Item = N>>( self, notifications: I, ) -> Self
Register multiple notification providers
Sourcepub fn sampler<S: McpSampling + 'static>(self, sampling: S) -> Self
pub fn sampler<S: McpSampling + 'static>(self, sampling: S) -> Self
Register a sampler - convenient alias for sampling_provider
Sourcepub fn completer<C: McpCompletion + 'static>(self, completion: C) -> Self
pub fn completer<C: McpCompletion + 'static>(self, completion: C) -> Self
Register a completer - convenient alias for completion_provider
Sourcepub fn notification_type<N: McpNotification + 'static + Default>(self) -> Self
pub fn notification_type<N: McpNotification + 'static + Default>(self) -> Self
Register a notification by type - type determines method automatically
Sourcepub fn handler<H: McpHandler + 'static>(self, handler: H) -> Self
pub fn handler<H: McpHandler + 'static>(self, handler: H) -> Self
Register a handler with the server
Sourcepub fn handlers<H: McpHandler + 'static, I: IntoIterator<Item = H>>(
self,
handlers: I,
) -> Self
pub fn handlers<H: McpHandler + 'static, I: IntoIterator<Item = H>>( self, handlers: I, ) -> Self
Register multiple handlers
Sourcepub fn with_completion(self) -> Self
pub fn with_completion(self) -> Self
Add completion support
Sourcepub fn with_prompts(self) -> Self
pub fn with_prompts(self) -> Self
Add prompts support
Sourcepub fn with_resources(self) -> Self
pub fn with_resources(self) -> Self
Add resources support
Sourcepub fn with_logging(self) -> Self
pub fn with_logging(self) -> Self
Add logging support
Sourcepub fn with_roots(self) -> Self
pub fn with_roots(self) -> Self
Add roots support
Sourcepub fn with_sampling(self) -> Self
pub fn with_sampling(self) -> Self
Add sampling support
Sourcepub fn with_elicitation(self) -> Self
pub fn with_elicitation(self) -> Self
Add elicitation support with default mock provider
Sourcepub fn with_elicitation_provider<P: ElicitationProvider + 'static>(
self,
provider: P,
) -> Self
pub fn with_elicitation_provider<P: ElicitationProvider + 'static>( self, provider: P, ) -> Self
Add elicitation support with custom provider
Sourcepub fn with_notifications(self) -> Self
pub fn with_notifications(self) -> Self
Add notifications support
Sourcepub fn session_timeout_minutes(self, minutes: u64) -> Self
pub fn session_timeout_minutes(self, minutes: u64) -> Self
Configure session timeout (in minutes, default: 30)
Sourcepub fn session_cleanup_interval_seconds(self, seconds: u64) -> Self
pub fn session_cleanup_interval_seconds(self, seconds: u64) -> Self
Configure session cleanup interval (in seconds, default: 60)
Sourcepub fn strict_lifecycle(self, strict: bool) -> Self
pub fn strict_lifecycle(self, strict: bool) -> Self
Enable strict MCP lifecycle enforcement
Sourcepub fn with_strict_lifecycle(self) -> Self
pub fn with_strict_lifecycle(self) -> Self
Enable strict MCP lifecycle enforcement (convenience method)
Sourcepub fn with_long_sessions(self) -> Self
pub fn with_long_sessions(self) -> Self
Configure sessions with recommended defaults for long-running sessions
Sourcepub fn with_short_sessions(self) -> Self
pub fn with_short_sessions(self) -> Self
Configure sessions with recommended defaults for short-lived sessions
Sourcepub fn storage(self, storage: Arc<BoxedSessionStorage>) -> Self
pub fn storage(self, storage: Arc<BoxedSessionStorage>) -> Self
Set the session storage backend
Supports all framework storage backends:
InMemorySessionStorage- For development and testingSqliteSessionStorage- For single-instance persistencePostgreSqlSessionStorage- For multi-instance deploymentsDynamoDbSessionStorage- For serverless AWS deployments
Sourcepub fn middleware(self, middleware: Arc<dyn McpMiddleware>) -> Self
pub fn middleware(self, middleware: Arc<dyn McpMiddleware>) -> Self
Register middleware for request/response interception
Middleware can inspect and modify requests before they reach handlers, inject data into sessions, and transform responses. Multiple middleware can be registered and will execute in FIFO order for before_dispatch and LIFO order for after_dispatch.
§Example
use std::sync::Arc;
use turul_mcp_aws_lambda::LambdaMcpServerBuilder;
use turul_http_mcp_server::middleware::McpMiddleware;
let builder = LambdaMcpServerBuilder::new()
.name("my-server")
.middleware(Arc::new(AuthMiddleware))
.middleware(Arc::new(RateLimitMiddleware));Sourcepub fn server_config(self, config: ServerConfig) -> Self
pub fn server_config(self, config: ServerConfig) -> Self
Configure server settings
Sourcepub fn stream_config(self, config: StreamConfig) -> Self
pub fn stream_config(self, config: StreamConfig) -> Self
Configure streaming/SSE settings
Sourcepub fn cors(self, config: CorsConfig) -> Self
pub fn cors(self, config: CorsConfig) -> Self
Set custom CORS configuration
Sourcepub fn cors_allow_all_origins(self) -> Self
pub fn cors_allow_all_origins(self) -> Self
Allow all origins for CORS (development only)
Sourcepub fn cors_allow_origins(self, origins: Vec<String>) -> Self
pub fn cors_allow_origins(self, origins: Vec<String>) -> Self
Set specific allowed origins for CORS
Sourcepub fn cors_from_env(self) -> Self
pub fn cors_from_env(self) -> Self
Configure CORS from environment variables
Uses these environment variables:
MCP_CORS_ORIGINS- Comma-separated list of allowed originsMCP_CORS_CREDENTIALS- Whether to allow credentials (true/false)MCP_CORS_MAX_AGE- Preflight cache max age in seconds
Sourcepub fn cors_disabled(self) -> Self
pub fn cors_disabled(self) -> Self
Disable CORS (headers will not be added)
Sourcepub fn development_config(self) -> Self
pub fn development_config(self) -> Self
Create with in-memory storage and permissive CORS
This is the recommended configuration for development and testing.
Sourcepub async fn build(self) -> Result<LambdaMcpServer>
pub async fn build(self) -> Result<LambdaMcpServer>
Build the Lambda MCP server
Returns a server that can create handlers when needed.
Trait Implementations§
Source§impl Default for LambdaMcpServerBuilder
impl Default for LambdaMcpServerBuilder
Source§impl LambdaMcpServerBuilderExt for LambdaMcpServerBuilder
impl LambdaMcpServerBuilderExt for LambdaMcpServerBuilder
Source§fn tools<I, T>(self, tools: I) -> Selfwhere
I: IntoIterator<Item = T>,
T: McpTool + 'static,
fn tools<I, T>(self, tools: I) -> Selfwhere
I: IntoIterator<Item = T>,
T: McpTool + 'static,
Auto Trait Implementations§
impl Freeze for LambdaMcpServerBuilder
impl !RefUnwindSafe for LambdaMcpServerBuilder
impl Send for LambdaMcpServerBuilder
impl Sync for LambdaMcpServerBuilder
impl Unpin for LambdaMcpServerBuilder
impl !UnwindSafe for LambdaMcpServerBuilder
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> 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