MCP2Lambda

by danilop

93 stars
Not rated
GitHub

About

Enables LLMs to interact with AWS Lambda functions, providing access to private resources, AWS services, and Lambda's capabilities for data processing and external API integration.

Details

Author
danilop
GitHub stars
93
Categories
Cloud Service, Other, Infrastructure, AI, Developer Tools, Search, API
Tags
#integration

Setup

Install MCP2Lambda in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/danilop/mcp2lambda

Follow the installation instructions in the repository README, then restart your MCP client.

Run anyAWS Lambdafunction as a Large Language Model (LLM)toolwithout code changes usingAnthropic'sModel Context Protocol (MCP).

graph LR A[Model] <--> B[MCP Client] B <--> C["MCP2Lambda<br>(MCP Server)"] C <--> D[Lambda Function] D <--> E[Other AWS Services] D <--> F[Internet] D <--> G[VPC] style A fill:#f9f,stroke:#333,stroke-width:2px style B fill:#bbf,stroke:#333,stroke-width:2px style C fill:#bfb,stroke:#333,stroke-width:4px style D fill:#fbb,stroke:#333,stroke-width:2px style E fill:#fbf,stroke:#333,stroke-width:2px style F fill:#dff,stroke:#333,stroke-width:2px style G fill:#ffd,stroke:#333,stroke-width:2px

This MCP server acts as abridgebetween MCP clients and AWS Lambda functions, allowing generative AI models to access and run Lambda functions as tools. This is useful, for example, to access private resources such as internal applications and databases without the need to provide public network access. This approach allows the model to use other AWS services, private networks, and the public internet.

From asecurityperspective, this approach implements segregation of duties by allowing the model to invoke the Lambda functions but not to access the other AWS services directly. The client only needs AWS credentials to invoke the Lambda functions. The Lambda functions can then interact with other AWS services (using the function role) and access public or private networks.

The MCP server gives access to two tools:
-

The first tool canautodiscoverall Lambda functions in your account that match a prefix or an allowed list of names. This tool shares the names of the functions and their descriptions with the model.

The second tool allows toinvokethose Lambda functions by name passing the required parameters.

No code changes are required. You should change these configurations to improve results:

The gateway supports two different strategies for handling Lambda functions:
-

Pre-Discovery Mode(default: enabled): Registers each Lambda function as an individual tool at startup. This provides a more intuitive interface where each function appears as its own named tool.

Generic Mode: Uses two generic tools (list_lambda_functionsandinvoke_lambda_function) to interact with Lambda functions.

- Environment variable:PRE_DISCOVERY=true|false
- CLI flag:--no-pre-discovery(disables pre-discovery mode)

# Disable pre-discovery mode export PRE_DISCOVERY=false python main.py # Or using CLI flag to disable pre-discovery python main.py --no-pre-discovery

-

To provide the MCP client with the knowledge to use a Lambda function, thedescription of the Lambda functionshould indicate what the function does and which parameters it uses. See the sample functions for a quick demo and more details.

To help the model use the tools available via AWS Lambda, you can add something like this to yoursystem prompt:

Use the AWS Lambda tools to improve your answers.

MCP2Lambda enables LLMs to interact with AWS Lambda functions as tools, extending their capabilities beyond text generation. This allows models to:

- Access real-time and private data, including data sources in your VPCs
- Execute custom code using a Lambda function as sandbox environment
- Interact with external services and APIs using Lambda functions internet access (and bandwidth)
- Perform specialized calculations or data processing

The server uses the MCP protocol, which standardizes the way AI models can access external tools.

By default, only functions whose name starts withmcp2lambda-will be available to the model.

- Python 3.12 or higher
- AWS account with configured credentials
- AWS Lambda functions (sample functions provided in the repo)
- An application usingAmazon Bedrockwith theConverse API
- An MCP-compatible client like
Claude Desktop

To install MCP2Lambda for Claude Desktop automatically viaSmithery:

npx -y @smithery/cli install @danilop/MCP2Lambda --client claude
git clone https://github.com/yourusername/mcp2lambda.git cd mcp2lambda

Configure AWS credentials. For example, using theAWS CLI:

This repository includes threesampleLambda functions that demonstrate different use cases. These functions have basic permissions and can only write to CloudWatch logs.

Retrieves a customer ID based on an email address. This function takes an email parameter and returns the associated customer ID, demonstrating how to build simple lookup tools. The function is hard coded to reply to theuser@example.comemail address. For example, you can ask the model to get the customer ID for the emailuser@example.com.

Retrieves detailed customer information based on a customer ID. This function returns customer details like name, email, and status, showing how Lambda can provide context-specific data. The function is hard coded to reply to the customer ID returned by the previous function. For example, you can ask the model to "Get the customer status for emailuser@example.com". This will use both functions to get to the result.

Executes arbitrary Python code within a Lambda sandbox environment. This powerful function allows Claude to write and run Python code to perform calculations, data processing, or other operations not built into the model. For example, you can ask the model to "Calculate the number of prime numbers between 1 and 10, 1 and 100, and so on up to 1M".

The repository includes sample Lambda functions in thesample_functionsdirectory.
-

Install the AWS SAM CLI:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html

cd sample_functions sam build sam deploy

The sample functions will be deployed with the prefixmcp2lambda-.

MCP2Lambda can also be used with Amazon Bedrock's Converse API, allowing you to use the MCP protocol with any of the models supported by Bedrock.

Themcp_client_bedrockdirectory contains a client implementation that connects MCP2Lambda to Amazon Bedrock models.

Seehttps://github.com/mikegc-aws/amazon-bedrock-mcpfor more information.

- Amazon Bedrock access and permissions to use models like Claude, Mistral, Llama, etc.
- Boto3 configured with appropriate credentials
-

Navigate to the mcp_client_bedrock directory:

The client is configured to use Anthropic's Claude 3.7 Sonnet by default, but you can modify themodel_idinmain.pyto use other Bedrock models:

# Examples of supported models: model_id = "us.anthropic.claude-3-7-sonnet-20250219-v1:0" #model_id = "us.amazon.nova-pro-v1:0"

You can also customize the system prompt in the same file to change how the model behaves.
-

Start the MCP2Lambda server in one terminal:

Run the Bedrock client in another terminal:

Interact with the model through the command-line interface. The model will have access to the Lambda functions deployed earlier.

Add the following to your Claude Desktop configuration file:

{ "mcpServers": { "mcp2lambda": { "command": "uv", "args": [ "--directory", "<full path to the mcp2lambda directory>", "run", "main.py" ] } } }

To help the model use tools via AWS Lambda, in your settings profile, you can add to your personal preferences a sentence like:

Use the AWS Lambda tools to improve your answers.

A command-line tool to automate the deployment of MCP servers to AWS ECS.

Core AWS MCP server providing prompt understanding and server management capabilities.

Analyze CDK projects to identify AWS services used and get pricing information from AWS pricing webpages and API.

Deploy and operate workloads, secrets, and networking across AWS, GCP, Azure, and private clouds.

Create, build, deploy, and manage Netlify resources using natural language.

Integrate with Alibaba Cloud APIs to manage resources like ECS, Cloud Monitor, and OOS.

Integrate with the Coolify API to manage your servers, applications, and databases.

An MCP server for interacting with the Coolify API to manage servers and applications.

An MCP server for integrating with Coolify, the self-hostable alternative to Netlify and Vercel.

Integrate with the Laravel Forge API to manage servers and deployments using MCP-compliant tools.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.