MCP ExplorerExplorer

Mcp Streamablehttp Lambda Sample

@moritalouson 9 months ago
18 MIT
FreeCommunity
AI Systems
A serverless application implementing a Streamable HTTP API using MCP on AWS Lambda.

Overview

What is Mcp Streamablehttp Lambda Sample

mcp-streamablehttp-lambda-sample is a serverless application that implements a Streamable HTTP API using the Model Context Protocol (MCP) on AWS Lambda. It serves as a proof of concept for deploying Lambda functions that support response streaming.

Use cases

Use cases for mcp-streamablehttp-lambda-sample include creating interactive chatbots, real-time calculators, and tools that require immediate feedback from user inputs.

How to use

To use mcp-streamablehttp-lambda-sample, you need to set up your local development environment with AWS CLI, SAM CLI, Node.js 22.x, and Docker. After cloning the repository, you can deploy the Lambda function using AWS SAM and access it via the provided Function URL.

Key features

Key features include tool invocation functionality using MCP, real-time responses through Lambda Response Streaming, and examples of simple echo and calculation tools.

Where to use

mcp-streamablehttp-lambda-sample can be used in fields that require serverless applications, real-time data processing, and applications that benefit from streaming APIs, such as chat applications, live data feeds, and interactive tools.

Content

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:

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

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers