Skip to content

moritalous/mcp-streamablehttp-lambda-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published