Skip to content

feat: add FastMCP Lambda template for MCP server scaffolding#420

Closed
aidandaly24 wants to merge 4 commits intoaws:feat/gateway-integrationfrom
aidandaly24:feat/batch-5-fastmcp-lambda-template
Closed

feat: add FastMCP Lambda template for MCP server scaffolding#420
aidandaly24 wants to merge 4 commits intoaws:feat/gateway-integrationfrom
aidandaly24:feat/batch-5-fastmcp-lambda-template

Conversation

@aidandaly24
Copy link
Contributor

@aidandaly24 aidandaly24 commented Feb 24, 2026

Description

Add a FastMCP Lambda template for scaffolding MCP servers that run on AWS Lambda with function URLs.

Currently, the python-lambda template uses a raw stdlib handler designed for Lambda gateway targets. This PR adds a new python-fastmcp-lambda template that uses the FastMCP library — a proper MCP server that speaks MCP protocol and is designed to sit behind an AgentCore gateway's mcpServer target type.

The template uses AWS Lambda Web Adapter with uvicorn to run FastMCP's Streamable HTTP app natively on Lambda. This replaces the original Mangum-based approach, which couldn't handle SSE/streaming responses required by the MCP Streamable HTTP protocol. The Lambda Web Adapter runs uvicorn as a sidecar process, and a bootstrap script (run.sh) starts the server on the port specified by the adapter.

Key configuration:

  • FastMCP(stateless_http=True, host="0.0.0.0") — stateless mode for Lambda, accept any Host header from function URL
  • server.py — FastAPI wrapper that mounts streamable_http_app() with proper lifespan management
  • run.sh — bootstrap script that runs uvicorn server:app on the Lambda Web Adapter port
  • pyproject.toml — dependencies: mcp >= 1.18.0, fastapi, uvicorn, httpx (no mangum)

The template includes sample HTTP tools (lookup_ip, get_random_user, fetch_post) for consistency with existing templates.

Changes:

  • New src/assets/mcp/python-fastmcp-lambda/ template directory (handler.py, server.py, run.sh, pyproject.toml, README.md)
  • Updated GatewayTargetRenderer.ts to select the new template when compute host is Lambda
  • Updated asset snapshot

The corresponding CDK changes (Lambda Web Adapter layer, AWS_LAMBDA_EXEC_WRAPPER, PORT env var, run.sh handler) are in CDK PR #53.

This template is used by the scaffolding flow added in a subsequent PR (Task 14).

Related Issue

Part of the MCP Gateway Phase 1 integration (gateway-integration branch). Task 13.

Type of Change

  • New feature

Testing

How have you tested the change?

  • I ran npm run test:unit and npm run test:integ
  • I ran npm run typecheck
  • I ran npm run lint
  • If I modified src/assets/, I ran npm run test:update-snapshots and committed the updated snapshots

End-to-end tested: scaffolded Lambda MCP server deployed via gateway, agent successfully invoked tools through the gateway.

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 24, 2026
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 24, 2026
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-fastmcp-lambda-template branch from 9421691 to 6ea432f Compare February 24, 2026 23:02
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 24, 2026
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 25, 2026
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-fastmcp-lambda-template branch from e30a275 to 80e1df6 Compare February 25, 2026 05:59
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 25, 2026
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-fastmcp-lambda-template branch from 80e1df6 to b1f312d Compare February 25, 2026 06:04
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 25, 2026
Add python-fastmcp-lambda template for scaffolding MCP servers that
run on AWS Lambda with function URLs. Uses FastMCP for tool definitions
and Mangum as the ASGI-to-Lambda adapter.

Template includes sample HTTP tools (lookup_ip, get_random_user,
fetch_post) matching the existing python/ template patterns.

Updates GatewayTargetRenderer to select this template when the
compute host is Lambda.
The CLI writes handler: 'handler.lambda_handler' in compute config.
The template must export lambda_handler, not handler.
@aidandaly24 aidandaly24 force-pushed the feat/batch-5-fastmcp-lambda-template branch from bee7adc to 9c3817b Compare February 25, 2026 19:23
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants