LambdaMcpServerBuilder

Struct LambdaMcpServerBuilder 

Source
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

Source

pub fn new() -> Self

Create a new Lambda MCP server builder

Source

pub fn name(self, name: impl Into<String>) -> Self

Set the server name

Source

pub fn version(self, version: impl Into<String>) -> Self

Set the server version

Source

pub fn title(self, title: impl Into<String>) -> Self

Set the server title

Source

pub fn instructions(self, instructions: impl Into<String>) -> Self

Set optional instructions for clients

Source

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
Source

pub fn tool_fn<F, T>(self, func: F) -> Self
where F: Fn() -> T, T: McpTool + 'static,

Register a function tool created with #[mcp_tool] macro

Source

pub fn tools<T: McpTool + 'static, I: IntoIterator<Item = T>>( self, tools: I, ) -> Self

Register multiple tools

Source

pub fn resource<R: McpResource + 'static>(self, resource: R) -> Self

Register a resource with the server

Source

pub fn resources<R: McpResource + 'static, I: IntoIterator<Item = R>>( self, resources: I, ) -> Self

Register multiple resources

Source

pub fn prompt<P: McpPrompt + 'static>(self, prompt: P) -> Self

Register a prompt with the server

Source

pub fn prompts<P: McpPrompt + 'static, I: IntoIterator<Item = P>>( self, prompts: I, ) -> Self

Register multiple prompts

Source

pub fn elicitation<E: McpElicitation + 'static>(self, elicitation: E) -> Self

Register an elicitation provider with the server

Source

pub fn elicitations<E: McpElicitation + 'static, I: IntoIterator<Item = E>>( self, elicitations: I, ) -> Self

Register multiple elicitation providers

Source

pub fn sampling_provider<S: McpSampling + 'static>(self, sampling: S) -> Self

Register a sampling provider with the server

Source

pub fn sampling_providers<S: McpSampling + 'static, I: IntoIterator<Item = S>>( self, sampling: I, ) -> Self

Register multiple sampling providers

Source

pub fn completion_provider<C: McpCompletion + 'static>( self, completion: C, ) -> Self

Register a completion provider with the server

Source

pub fn completion_providers<C: McpCompletion + 'static, I: IntoIterator<Item = C>>( self, completions: I, ) -> Self

Register multiple completion providers

Source

pub fn logger<L: McpLogger + 'static>(self, logger: L) -> Self

Register a logger with the server

Source

pub fn loggers<L: McpLogger + 'static, I: IntoIterator<Item = L>>( self, loggers: I, ) -> Self

Register multiple loggers

Source

pub fn root_provider<R: McpRoot + 'static>(self, root: R) -> Self

Register a root provider with the server

Source

pub fn root_providers<R: McpRoot + 'static, I: IntoIterator<Item = R>>( self, roots: I, ) -> Self

Register multiple root providers

Source

pub fn notification_provider<N: McpNotification + 'static>( self, notification: N, ) -> Self

Register a notification provider with the server

Source

pub fn notification_providers<N: McpNotification + 'static, I: IntoIterator<Item = N>>( self, notifications: I, ) -> Self

Register multiple notification providers

Source

pub fn sampler<S: McpSampling + 'static>(self, sampling: S) -> Self

Register a sampler - convenient alias for sampling_provider

Source

pub fn completer<C: McpCompletion + 'static>(self, completion: C) -> Self

Register a completer - convenient alias for completion_provider

Source

pub fn notification_type<N: McpNotification + 'static + Default>(self) -> Self

Register a notification by type - type determines method automatically

Source

pub fn handler<H: McpHandler + 'static>(self, handler: H) -> Self

Register a handler with the server

Source

pub fn handlers<H: McpHandler + 'static, I: IntoIterator<Item = H>>( self, handlers: I, ) -> Self

Register multiple handlers

Source

pub fn root(self, root: Root) -> Self

Add a single root directory

Source

pub fn with_completion(self) -> Self

Add completion support

Source

pub fn with_prompts(self) -> Self

Add prompts support

Source

pub fn with_resources(self) -> Self

Add resources support

Source

pub fn with_logging(self) -> Self

Add logging support

Source

pub fn with_roots(self) -> Self

Add roots support

Source

pub fn with_sampling(self) -> Self

Add sampling support

Source

pub fn with_elicitation(self) -> Self

Add elicitation support with default mock provider

Source

pub fn with_elicitation_provider<P: ElicitationProvider + 'static>( self, provider: P, ) -> Self

Add elicitation support with custom provider

Source

pub fn with_notifications(self) -> Self

Add notifications support

Source

pub fn session_timeout_minutes(self, minutes: u64) -> Self

Configure session timeout (in minutes, default: 30)

Source

pub fn session_cleanup_interval_seconds(self, seconds: u64) -> Self

Configure session cleanup interval (in seconds, default: 60)

Source

pub fn strict_lifecycle(self, strict: bool) -> Self

Enable strict MCP lifecycle enforcement

Source

pub fn with_strict_lifecycle(self) -> Self

Enable strict MCP lifecycle enforcement (convenience method)

Source

pub fn sse(self, enable: bool) -> Self

Enable or disable SSE streaming support

Source

pub fn with_long_sessions(self) -> Self

Configure sessions with recommended defaults for long-running sessions

Source

pub fn with_short_sessions(self) -> Self

Configure sessions with recommended defaults for short-lived sessions

Source

pub fn storage(self, storage: Arc<BoxedSessionStorage>) -> Self

Set the session storage backend

Supports all framework storage backends:

  • InMemorySessionStorage - For development and testing
  • SqliteSessionStorage - For single-instance persistence
  • PostgreSqlSessionStorage - For multi-instance deployments
  • DynamoDbSessionStorage - For serverless AWS deployments
Source

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));
Source

pub fn server_config(self, config: ServerConfig) -> Self

Configure server settings

Source

pub fn stream_config(self, config: StreamConfig) -> Self

Configure streaming/SSE settings

Source

pub fn cors(self, config: CorsConfig) -> Self

Set custom CORS configuration

Source

pub fn cors_allow_all_origins(self) -> Self

Allow all origins for CORS (development only)

Source

pub fn cors_allow_origins(self, origins: Vec<String>) -> Self

Set specific allowed origins for CORS

Source

pub fn cors_from_env(self) -> Self

Configure CORS from environment variables

Uses these environment variables:

  • MCP_CORS_ORIGINS - Comma-separated list of allowed origins
  • MCP_CORS_CREDENTIALS - Whether to allow credentials (true/false)
  • MCP_CORS_MAX_AGE - Preflight cache max age in seconds
Source

pub fn cors_disabled(self) -> Self

Disable CORS (headers will not be added)

Source

pub fn development_config(self) -> Self

Create with in-memory storage and permissive CORS

This is the recommended configuration for development and testing.

Source

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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl LambdaMcpServerBuilderExt for LambdaMcpServerBuilder

Source§

fn tools<I, T>(self, tools: I) -> Self
where I: IntoIterator<Item = T>, T: McpTool + 'static,

Add multiple tools at once

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,