Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AIFire in da houseCheck it out free

mcp-streamablehttp-lambda-sample

MCP.Pizza Chef: moritalous

mcp-streamablehttp-lambda-sample is a serverless MCP server implemented as an AWS Lambda function supporting real-time response streaming and tool invocation. It leverages AWS SAM for deployment and Node.js 22.x runtime, enabling efficient streaming HTTP APIs with MCP protocol integration. This server demonstrates practical examples like greeting tools and notifications, showcasing MCP's capabilities in a scalable, event-driven cloud environment.

Use This MCP server To

Deploy serverless MCP APIs with real-time streaming responses Invoke MCP tools within AWS Lambda functions Implement streaming HTTP APIs using MCP on AWS Demonstrate simple greeting and notification tools via MCP Integrate MCP protocol in serverless cloud architectures

README

Streamable MCP Lambda Function

This project is a serverless application that implements a Streamable HTTP API using the Model Context Protocol (MCP) on AWS Lambda.

Project Overview

This application deploys a Lambda function that supports response streaming using AWS SAM (Serverless Application Model). The main features include:

  • Tool invocation functionality using the Model Context Protocol (MCP)
  • Real-time responses utilizing Lambda Response Streaming
  • Implementation examples of simple greeting tools and notification capabilities

About the Libraries Used

This project uses the Model Context Protocol (MCP) TypeScript library.

Architecture

This application consists of the following components:

  • MCPStreamableFunction: Lambda function using Node.js 22.x runtime
  • Lambda Adapter Layer: Layer to support response streaming
  • Function URL: Endpoint for direct access to the Lambda function without authentication

Prerequisites

To use this project, you need:

  • AWS CLI
  • SAM CLI
  • Node.js 22.x
  • Docker

Setup and Deployment

Setting up the Local Development Environment

# Clone the repository
git clone https://github.com/moritalous/mcp-streamablehttp-lambda-sample.git
# Navigate to the project directory
cd mcp-streamablehttp-lambda-sample

# Install dependencies
cd mcp-function
npm install
cd ..

Build and Deploy

# Build the application
sam build

# Deploy the application (interactive for the first time)
sam deploy --guided

During deployment, you will be prompted to enter the following information:

  • Stack Name: Name of the CloudFormation stack (e.g., mcp-server-streamable-http)
  • AWS Region: Region to deploy to
  • Confirm changes before deploy: Whether to confirm changes
  • Allow SAM CLI IAM role creation: Whether to allow IAM role creation
  • Save arguments to samconfig.toml: Whether to save the configuration

After deployment completes, the Lambda Function URL will be output. You can use this URL to access the API.

Features and Endpoints

This application provides the following endpoints:

  • POST /mcp: Initialize and send MCP requests
  • GET /mcp: Method not allowed (returns 405)
  • DELETE /mcp: Method not allowed (returns 405)

Implemented Tools

This sample application implements the following tools:

  1. greet: A simple greeting tool

    • Parameter: name (string)
  2. multi-greet: A tool that sends multiple greetings with notifications

    • Parameter: name (string)
  3. greeting-template: A prompt template for generating greetings

    • Parameter: name (string)
  4. greeting-resource: A resource that provides a default greeting

Client Implementation

A client implementation example is available in mcp-function/src/client.ts. This client provides an interactive command-line interface to:

  1. Connect to the server
  2. List available tools, prompts, and resources
  3. Call tools with arguments
  4. Get prompts with arguments
  5. Handle notifications from the server
  6. Manage session termination and reconnection

Testing Connection from Local to Lambda

cd mcp-function

MCP_SERVER_URL=https://*****.lambda-url.us-east-1.on.aws/mcp npm run dev:client

Resource Cleanup

To remove resources when no longer needed:

sam delete --stack-name <your-stack-name>

Additional Information

mcp-streamablehttp-lambda-sample FAQ

How does this MCP server handle real-time streaming responses?
It uses AWS Lambda Response Streaming to deliver data incrementally during HTTP requests.
What runtime environment does this MCP server use?
It runs on Node.js 22.x within AWS Lambda.
How is tool invocation implemented in this MCP server?
Tool invocation is supported via the Model Context Protocol integrated into the Lambda function.
What deployment framework is used for this MCP server?
AWS Serverless Application Model (SAM) is used for deployment and infrastructure management.
Can this MCP server be extended with custom tools?
Yes, developers can add custom MCP tools within the Lambda function environment.
What libraries does this MCP server rely on?
It uses the official MCP TypeScript library from the Anthropics GitHub repository.
Is this MCP server suitable for production workloads?
Yes, it is designed for scalable, serverless deployments on AWS Lambda with streaming capabilities.
How does the Lambda Adapter Layer contribute to this MCP server?
It enables response streaming support within the Lambda function environment.