Skip to content

Recommended deployment pattern for FastMCP on AWS Lambda using Mangum #3121

Description

@shoaib1207k

Question

Hi! I'm deploying a FastMCP server on AWS Lambda using Mangum and wanted to check if I'm following the recommended deployment pattern.

I created the FastMCP instance globally so that tool registration only happens during Lambda cold starts.

# mcp_server.py
mcp = FastMCP(...)

# lambda_handler.py
from mangum import Mangum
from mcp_server import mcp

app = mcp.streamable_http_app()
handler = Mangum(app)

The first invocation succeeds, but subsequent warm invocations fail with:

StreamableHTTPSessionManager.run() can only be called once per instance

Working approach

The only approach I've found that works consistently is recreating the FastMCP instance for every invocation:

def handler(event, context):
    mcp = create_mcp()
    app = mcp.streamable_http_app()
    return Mangum(app)(event, context)

This resolves the issue, but it also means tool registration and server initialization happen on every request instead of only during cold starts.

Is recreating the FastMCP instance per Lambda invocation the recommended deployment pattern?

Or is there a supported way to reuse a global FastMCP instance across warm Lambda invocations while using Mangum?

If this is expected behavior, I'd also appreciate any guidance on the recommended deployment pattern for FastMCP on AWS Lambda.

Thanks!

Additional Context

Environment:-

  • MCP Python SDK: 1.28.1
  • Python: 3.12
  • Mangum: 0.21.0
  • AWS Lambda (Function URL)
  • Transport: streamable-http

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions