How danilop/mcp2lambda works
Project Type and Purpose
• The project is a bridge between generative AI models (LLMs) and AWS Lambda functions. It implements the Model Context Protocol (MCP) and provides an MCP server (MCP2Lambda) that enables AI models (such as those used with Amazon Bedrock or Claude Desktop) to discover and invoke AWS Lambda functions as “tools.”
• It also includes a client implementation (in the mcp_client_bedrock directory) designed to integrate with Amazon Bedrock by using the Converse API.
• Additionally, sample Lambda functions are provided (under sample_functions) to demonstrate various use cases like retrieving customer data or running Python code in a sandbox.
Analyzing the File Structure
• At the top level, you have core files (e.g., main.py, Dockerfile, pyproject.toml) that configure and launch the MCP server.
• The mcp_client_bedrock directory contains its own main.py and supporting modules (converse_agent.py, converse_tools.py, mcp_client.py) showing the client-side integration.
• The sample_functions directory contains three separate sample Lambda functions (customer-id-from-email, customer-info-from-id, and run-python-code) along with SAM templates and configuration files for deploying these Lambda functions.
• Additional configuration files such as smithery.yaml, uv.lock, and .python-version provide insights into the development and deployment environment.
Key Components and Their Relationships
a) Main Components:
• Model (LLM): Represents the AI model (e.g., Anthropic’s Claude or other Bedrock models) that will drive requests.
• MCP Client: The component (e.g., in mcp_client_bedrock) that connects the AI model to the MCP server.
• MCP2Lambda Server: The heart of the project that bridges between the MCP client and the AWS Lambda functions.
• AWS Lambda Functions: Deployed functions (both discovered automatically and registered individually) which execute specific operations.
• External AWS Services/Networks: While the Lambda functions can interact with AWS services, private networks (VPC), and even the Internet, they are reached only indirectly through the MCP server.
b) Interactions:
• The LLM sends requests via an MCP client.
• The client communicates with the MCP2Lambda server, which in turn manages the registration (and optionally pre-discovery) of Lambda functions.
• The MCP2Lambda server exposes two tools (discovery and invocation) that the model can use.
• Invocation requests cause the MCP2Lambda server to trigger the appropriate Lambda function.
• Lambda functions then can use their execution role to safely interact with other AWS services, internal systems, or even the public internet.
• This separation ensures a clear boundary; the model never interacts directly with AWS services.
Architectural Patterns & Design Principles
• The design follows a client-server model where the MCP2Lambda server encapsulates the logic for Lambda discovery and invocation.
• It implements segregation of duties: the model is only granted the ability to trigger Lambda functions while the functions themselves have the credentials for interacting with AWS services.
• The server also supports two operational strategies (Pre-Discovery and Generic modes). Therefore, the architecture must capture this decision point.
• The integration with AWS SAM emphasizes a deployment pattern for serverless functions and a clear separation between deployment (sample_functions with SAM templates) and runtime (server and client code).