# danilop/mcp2lambda architecture

> Architecture diagram of the GitHub repository danilop/mcp2lambda, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/danilop/mcp2lambda
- Repository: https://github.com/danilop/mcp2lambda

## Overview

##### 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).

## Diagram (Mermaid)

```mermaid
flowchart TD
    LLM["Model (LLM)"]:::frontend
    MCPClient["MCP Client (Bedrock)"]:::frontend
    MCPServer["MCP2Lambda Server\n(Pre-Discovery|Generic)"]:::backend
    LambdaFunctions["AWS Lambda Functions (Sample Functions)"]:::lambda

    LLM -->|"requests"| MCPClient
    MCPClient -->|"communicates"| MCPServer
    MCPServer -->|"invokes"| LambdaFunctions
    LambdaFunctions -->|"triggers"| AWSService
    LambdaFunctions -->|"triggers"| Internet
    LambdaFunctions -->|"triggers"| VPC

    subgraph "AWS Infrastructure"
        AWSService["Other AWS Services"]:::external
        Internet["Internet"]:::external
        VPC["VPC"]:::external
    end

    click MCPServer "https://github.com/danilop/mcp2lambda/blob/main/main.py"
    click MCPServer "https://github.com/danilop/mcp2lambda/tree/main/Dockerfile"
    click MCPServer "https://github.com/danilop/mcp2lambda/blob/main/pyproject.toml"
    click MCPClient "https://github.com/danilop/mcp2lambda/tree/main/mcp_client_bedrock/"
    click LambdaFunctions "https://github.com/danilop/mcp2lambda/tree/main/sample_functions/"

    classDef frontend fill:#CDE7FF,stroke:#1D6FA3,stroke-width:2px;
    classDef backend fill:#D5E8D4,stroke:#82B366,stroke-width:2px;
    classDef lambda fill:#FFF2CC,stroke:#E6B800,stroke-width:2px;
    classDef external fill:#F8CECC,stroke:#B85450,stroke-width:2px;
```
