Logo Lambda MCP Server

Lambda MCP Server

Cộng đồng
mikegc-aws

Creates a simple MCP tool server with "streaming" HTTP.

Nhà phát hànhmikegc-aws
Kho mãLambda-MCP-Server
Ngôn ngữPython
Bản fork
49
Sao
236
Công cụ có sẵn
0
Phương thức truyền tảistdio
Giấy phépMIT-0
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    Lambda MCP Server cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    236 sao và 49 bản fork từ kho mã được liên kết.

Lambda MCP Server Demo (Streamable HTTP)

⚠️ IMPORTANT: The Lambda MCP Server module code IS maintained, just not in this repository. It is now hosted and maintained at awslabs/mcp-lambda-handler. This repository remains as sample code of how to use the module.

To use the Lambda MCP Server, install the package directly from PyPI:

bash
pip install awslabs.mcp_lambda_handler
# or, if using uv:
uv add awslabs.mcp_lambda_handler

This server requires a client that supports Streamable HTTP (not SSE). There are a few MCP clients that currently support Streamable HTTP including the MCP Inspector. There is also as a Streamable HTTP client included in this repo, built Strands Agents.

This project demonstrates a powerful and developer-friendly way to create serverless MCP (Model Context Protocol) tools using AWS Lambda. It showcases how to build a stateless, serverless MCP server with minimal boilerplate and an excellent developer experience.

the_context()

In an episode of the_context, Tiffany Souterre and Mike discussed streamable HTTP for MCP as well as running (an older version of) this project:

Example

Here is the minimal code to get an MCP server running in an AWS Lambda function:

python
from awslabs.mcp_lambda_handler import MCPLambdaHandler

mcp_server = MCPLambdaHandler(name="mcp-lambda-server", version="1.0.0")

@mcp_server.tool()
def get_time() -> str:
    from datetime import datetime, UTC
    return datetime.now(UTC).isoformat()

def lambda_handler(event, context):
    return mcp_server.handle_request(event, context)

Session State Management

The Lambda MCP Server includes built-in session state management that persists across tool invocations within the same conversation. This is particularly useful for tools that need to maintain context or share data between calls.

Session data is stored in a DynamoDB table against a sessionId key. This is all managed for you.

Here's an example of how to use session state:

python
from lambda_mcp.lambda_mcp import LambdaMCPServer

session_table = os.environ.get('MCP_SESSION_TABLE', 'mcp_sessions')

mcp_server = LambdaMCPServer(name="mcp-lambda-server", version="1.0.0", session_store=session_table)

@mcp_server.tool()
def increment_counter() -> int:
    """Increment a session-based counter."""
    # Get the current counter value from session state, default to 0 if not set
    counter = mcp_server.session.get('counter', 0)
    
    # Increment the counter
    counter += 1
    
    # Store the new value in session state
    mcp_server.session['counter'] = counter
    
    return counter

@mcp_server.tool()
def get_counter() -> int:
    """Get the current counter value."""
    return mcp_server.session.get('counter', 0)

The session state is automatically managed per conversation and persists across multiple tool invocations. This allows you to maintain stateful information without needing additional external storage, while still keeping your Lambda function stateless.

Authentication

The sample server stack uses Bearer token authentication via an Authorization header, which is compliant with the MCP standard. This provides a basic level of security for your MCP server endpoints. Here's what you need to know:

  1. Bearer Token: When you deploy the stack, a bearer token is configured through a custom authorizer in API Gateway

  2. Using the Bearer Token:

    • The client must include the bearer token in requests using the Authorization header with the format: Bearer <your-token>
    • The token value is provided in the stack outputs after deployment
    • The sample client is configured to automatically include this header when provided with the token
  3. Custom Authorizer: The implementation uses a simple custom authorizer that validates a single bearer token. This can be easily extended or replaced with more sophisticated authentication systems like Amazon Cognito for production use.

⚠️ Security Note: While bearer token authentication provides a standard-compliant authentication mechanism, consider implementing additional security measures such as:

  • AWS IAM roles and policies
  • OAuth 2.0 / JWT with proper token management
  • Amazon Cognito User Pools

The current bearer token implementation is primarily intended for demonstration and development purposes. For production systems handling sensitive data, implement appropriate additional security measures based on your specific requirements.

What is this all about?

This is a proof-of-concept implementation of an MCP server running on AWS Lambda, along with a Strands Agents client that demonstrates its functionality. The project consists of two main components:

  1. Lambda MCP Server: A Python-based serverless implementation that makes it incredibly simple to deploy cloud hosted MCP tools.
  2. Strands Agents Client: A demonstration client that shows how to interact with the Lambda MCP server using Strands Agents.

Example Tools

The server comes with three example tools that demonstrate different use cases:

  1. get_weather(city: str): Get the current weather for a city. Returns a simulated temperature for the given city.
  2. count_s3_buckets(): Count the number of S3 buckets in your AWS account.
  3. get_time(): Get the current UTC date and time, and show how long since last time was asked for (if session available).

Getting Started

Prerequisites

Amazon Bedrock Setup

Before running the client, ensure you have:

  1. Enabled Amazon Bedrock access in your AWS account
  2. Enabled the Amazon Nova Models in your Bedrock model access settings
  3. Appropriate IAM permissions to invoke Bedrock APIs

Server Deployment

  1. Clone this repository:

    bash
    git clone <repository-url>
  2. Navigate to the server directory:

    bash
    cd server-http-python-lambda
  3. Deploy using SAM:

    bash
    sam build && sam deploy --guided

    Note: You will be prompted for an McpAuthToken. This is the Authorization Bearer token that will be requitred to call the endpoint. This simple implimentation uses an AWS API Gateway authorizers with the McpAuthToken passed in as an env var. This can be swapped out for a production implimentation as required.

Client Setup

  1. Update the api_gateway_url and auth_token in ./client-strands-agents-mcp/main.py:

    bash
    cd client-strands-agents-mcp
  2. Navigate to the client directory:

    bash
    cd client-strands-agents-mcp
  3. Run the helper script:

    bash
    uv sync
    uv run main.py

Adding New Tools

The Lambda MCP Server is designed to make tool creation as simple as possible. Here's how to add a new tool:

  1. Open server/app.py
  2. Add your new tool using the decorator pattern:
python
@mcp_server.tool()
def my_new_tool(param1: str, param2: int) -> str:
    """Your tool description.
    
    Args:
        param1: Description of param1
        param2: Description of param2
        
    Returns:
        Description of return value
    """
    # Your tool implementation
    return f"Processed {param1} with value {param2}"

That's it! The decorator handles:

  • Type validation
  • Request parsing
  • Response formatting
  • Error handling
  • MCP Documentation generation

Notes

Security

See CONTRIBUTING for more information.

For AWS security best practices, refer to the AWS Security Documentation and Amazon Bedrock security best practices.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

Changes

Version 2.0.0

  • The Lambda MCP Server module code is no longer included in this repository; it is now maintained at awslabs/mcp-lambda-handler.
  • Updated installation instructions to use the PyPI package: pip install awslabs.mcp_lambda_handler or uv add awslabs.mcp_lambda_handler.
  • README example code now uses the new package import and shows a minimal Lambda MCP server example.
  • Updated the list and descriptions of example tools to match the current implementation in app.py.
  • Updated client instructions to use Strands Agents and removed references to the TypeScript client.
  • Updated prerequisites and deployment instructions for clarity and accuracy.
  • Improved documentation for session state management and authentication.
  • Various documentation and usability improvements throughout the README.

Version 1.1.0

  • Replaced API Key authentication with Bearer token authentication via Authorization header
  • Added custom authorizer to API Gateway for token validation
  • Updated client configuration to use bearer tokens
  • Made authentication system compliant with MCP standard
  • Added this change log section

Version 1.0.0

  • Initial release
  • Basic MCP server implementation with AWS Lambda
  • Session state management with DynamoDB
  • Example tools implementation
  • TypeScript HTTP client with Amazon Bedrock integration

Dùng MCP Lambda MCP Server với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối Lambda MCP Server, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm Lambda MCP Server làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của Lambda MCP Server.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "lambda-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của Lambda MCP Server, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của Lambda MCP Server.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng Lambda MCP Server giúp tôi làm việc này không?
Lambda MCP Server
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng Lambda MCP Server.

Câu hỏi thường gặp

Máy chủ MCP Lambda MCP Server dùng để làm gì?

Lambda MCP Server là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP Lambda MCP Server với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng Lambda MCP Server với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP Lambda MCP Server với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối Lambda MCP Server, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP Lambda MCP Server với TypingMind?

Lambda MCP Server hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP Lambda MCP Server cung cấp những công cụ nào trong TypingMind?

Lambda MCP Server cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP Lambda MCP Server không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu Lambda MCP Server yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇