Lambda Layer MCP server

Lightweight AWS Lambda layer for streaming Server-Sent Events (SSE) that simplifies creating Lambda functions with complex transport and protocol handling for tool and prompt configuration.
Back to servers
Setup instructions
Provider
Mark Van Proctor
Release date
Mar 17, 2025
Language
TypeScript
Package
Stats
1.1K downloads
11 stars

This is an implementation of the Model Context Protocol (MCP) using AWS Lambda and the Serverless Application Model (SAM). It provides a serverless infrastructure for managing tools, resources, and prompts through AWS services, enabling streaming communication with client applications.

Installation Options

Option 1: Using AWS Serverless Application Repository (SAR)

  1. Go to the AWS Serverless Application Repository Console
  2. Search for mcp-lambda-sam by Mark Van Proctor
  3. Click Deploy
  4. Configure your parameters:
    • StackIdentifier: Unique ID for this MCP server instance
    • VpcEnabled: Set to true if deploying in a VPC
    • VpcId and SubnetIds: Provide if using VPC

Alternatively, deploy via AWS CLI:

aws serverlessrepo create-cloud-formation-change-set \
  --application-id arn:aws:serverlessrepo:ap-southeast-2:522814717816:applications/mcp-lambda-sam \
  --stack-name your-stack-name \
  --capabilities CAPABILITY_IAM \
  --parameter-overrides '[{"name":"StackIdentifier","value":"your-stack-id"}]'

Option 2: Using npx (CLI)

npx @markvp/mcp-lambda-sam deploy

This command will interactively prompt for:

  • Stack name
  • AWS Region
  • VPC configuration (optional)

Option 3: Programmatic Usage

First, install the package:

npm install @markvp/mcp-lambda-sam

Then use it in your code:

import { deploy } from '@markvp/mcp-lambda-sam';

// Deploy the MCP server
deploy();

Option 4: Local Development and Deployment

# Install dependencies
npm install @markvp/mcp-lambda-sam

# Deploy
npm run deploy

Administrator Guide

Setting Up Permissions

To grant access to the registration function URL:

aws lambda add-permission \
  --function-name <registration-function-name> \
  --statement-id allow-registration \
  --action lambda:InvokeFunctionUrl \
  --principal "*" \
  --function-url-auth-type IAM

To grant access to the MCP function URL:

aws lambda add-permission \
  --function-name <mcp-function-name> \
  --statement-id allow-mcp \
  --action lambda:InvokeFunctionUrl \
  --principal "*" \
  --function-url-auth-type IAM

Required IAM Permissions for Administrators

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": "lambda:InvokeFunctionUrl",
    "Resource": "arn:aws:lambda:${region}:${account}:function:${stack-id}-mcp-registration",
    "Condition": {
      "StringEquals": {
        "lambda:FunctionUrlAuthType": "AWS_IAM"
      }
    }
  }]
}

Registration API

Register a New Tool

awscurl -X POST ${REGISTRATION_URL}/register \
  --region ap-southeast-2 \
  --service lambda \
  -H "Content-Type: application/json" \
  -d '{
    "type": "tool",
    "name": "example",
    "description": "Example tool",
    "lambdaArn": "arn:aws:lambda:region:account:function:name",
    "parameters": {
      "input": "string"
    }
  }'

Update Registration

awscurl -X PUT ${REGISTRATION_URL}/register/{id} \
  --region ap-southeast-2 \
  --service lambda \
  -d '...'

Delete Registration

awscurl -X DELETE ${REGISTRATION_URL}/register/{id} \
  --region ap-southeast-2 \
  --service lambda

List Registrations

awscurl ${REGISTRATION_URL}/register \
  --region ap-southeast-2 \
  --service lambda

Client Usage Guide

Required IAM Permissions for Clients

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "lambda:InvokeFunctionUrl",
            "Resource": [
                "arn:aws:lambda:${region}:${account}:function:${stack-id}-mcp",
            ],
            "Condition": {
                "StringEquals": {
                    "lambda:FunctionUrlAuthType": "AWS_IAM"
                }
            }
        }
    ]
}

Connecting to the Server

Establish an SSE Connection

const sse = new EventSource(SSE_URL, {
  headers: { 
    Authorization: 'AWS4-HMAC-SHA256 ...', // Must be AWS SigV4 signed
  }
});

sse.onmessage = (event) => {
  console.log(JSON.parse(event.data));
};

Using cURL:

awscurl -X GET "${MCP_URL}/sse" \
  --region ap-southeast-2 \
  --service lambda

The first event will include a sessionId which you'll need for sending messages.

Send Commands

awscurl -X POST "${MCP_URL}/message?sessionId=session-123" \
  --region ap-southeast-2 \
  --service lambda \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": "1",
    "method": "example",
    "params": {
      "input": "hello"
    }
  }'

Error Handling

Common Client Errors

  • 401: Invalid/missing AWS credentials
  • 403: Insufficient permissions
  • 404: Invalid session ID
  • 429: Rate limit exceeded

Troubleshooting Tips

  1. Connection Issues:

    • Verify AWS credentials
    • Check IAM permissions
    • Ensure network connectivity
  2. Command Execution Errors:

    • Verify session ID is active
    • Check command format matches tool registration
    • Ensure parameters match schema

System Requirements

  • AWS CLI installed and configured
  • AWS SAM CLI installed
  • Node.js 20.x or later
  • An AWS account with permissions to create:
    • Lambda functions
    • DynamoDB tables
    • IAM roles
    • SQS queues

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mcp-lambda-sam" '{"command":"npx","args":["@markvp/mcp-lambda-sam"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "mcp-lambda-sam": {
            "command": "npx",
            "args": [
                "@markvp/mcp-lambda-sam"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "mcp-lambda-sam": {
            "command": "npx",
            "args": [
                "@markvp/mcp-lambda-sam"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later