MCP2Lambda
MCP2Lambda
Run any AWS Lambda function as a Large Language Model (LLM) tool without code changes using Anthropic's Model Control Protocol (MCP).
This MCP server acts as a bridge between 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 a security perspective, 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 can autodiscover all 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 to invoke those Lambda functions by name passing the required parameters.
No code changes are required. You should change these configurations to improve results:
- To provide the MCP client with the knowledge to use a Lambda function, the description of the Lambda function should 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 your system prompt:
Overview
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 with mcp2lambda-
will be available to the model.
Prerequisites
- Python 3.12 or higher
- AWS account with configured credentials
- AWS Lambda functions (sample functions provided in the repo)
- An application using Amazon Bedrock with the Converse API
- An MCP-compatible client like Claude Desktop
Installation
Installing via Smithery
To install MCP2Lambda for Claude Desktop automatically via Smithery:
Manual Installation
- Clone the repository:Copy
- Configure AWS credentials. For example, using the AWS CLI:Copy
Sample Lambda Functions
This repository includes three sample Lambda functions that demonstrate different use cases. These functions have basic permissions and can only write to CloudWatch logs.
CustomerIdFromEmail
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 the user@example.com
email address. For example, you can ask the model to get the customer ID for the email user@example.com
.
CustomerInfoFromId
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 email user@example.com
". This will use both functions to get to the result.
RunPythonCode
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".
Deploying Sample Lambda Functions
The repository includes sample Lambda functions in the sample_functions
directory.
- Install the AWS SAM CLI: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html
- Deploy the sample functions:Copy
The sample functions will be deployed with the prefix mcp2lambda-
.
Using with Amazon Bedrock
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.
The mcp_client_bedrock
directory contains a client implementation that connects MCP2Lambda to Amazon Bedrock models.
See https://github.com/mikegc-aws/amazon-bedrock-mcp for more information.
Prerequisites
- Amazon Bedrock access and permissions to use models like Claude, Mistral, Llama, etc.
- Boto3 configured with appropriate credentials
Installation and Setup
- Navigate to the mcp_client_bedrock directory:Copy
- Install dependencies:Copy
- Run the client:Copy
Configuration
The client is configured to use Anthropic's Claude 3.7 Sonnet by default, but you can modify the model_id
in main.py
to use other Bedrock models:
You can also customize the system prompt in the same file to change how the model behaves.
Usage
- Start the MCP2Lambda server in one terminal:Copy
- Run the Bedrock client in another terminal:Copy
- Interact with the model through the command-line interface. The model will have access to the Lambda functions deployed earlier.
Using with Claude Desktop
Add the following to your Claude Desktop configuration file:
To help the model use tools via AWS Lambda, in your settings profile, you can add to your personal preferences a sentence like:
Starting the MCP Server
Start the MCP server locally:
This server cannot be installed
Enables AI models to interact with AWS Lambda functions via the MCP protocol, allowing access to private resources, real-time data, and custom computation in a secure environment.