شعار Lambda MCP Server

Lambda MCP Server

المجتمع
mikegc-aws

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

الناشرmikegc-aws
المستودعLambda-MCP-Server
اللغةPython
التفريعات
49
النجوم
236
الأدوات المتاحة
0
نوع نقل البياناتstdio
الترخيصMIT-0
الروابط
  • اربط الأدوات بسير عمل الذكاء الاصطناعي

    يتيح Lambda MCP Server إمكانات MCP التي يمكن لتطبيقات الذكاء الاصطناعي العميلة ووكلاء الذكاء الاصطناعي المتوافقة استخدامها.

  • الأدوات المتاحة: 0

    تصفّح الإجراءات القابلة للاستدعاء أدناه، بما في ذلك أسماؤها وأوصافها عندما يوفّرها الخادم.

  • إعدادات جاهزة للنسخ

    استخدم أمثلة إعداد التثبيت لتهيئة هذا الخادم في تطبيق MCP العميل المفضّل لديك.

  • مؤشرات الاهتمام بالمصدر المفتوح

    النجوم: 236، والنسخ المتفرعة: 49 في المستودع المرتبط.

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

استخدم MCP الخاص بـ Lambda MCP Server مع نماذج ذكاء اصطناعي متعددة

يربط TypingMind أدوات MCP على مستوى مساحة العمل، لذا بمجرد توصيل Lambda MCP Server، يمكنك استخدامه مع نماذج ذكاء اصطناعي مختلفة في TypingMind بدلًا من إعداده لكل نموذج على حدة. يعمل تكامل MCP هذا محليًا عبر موصل MCP الخاص بـ TypingMind على جهازك.

دليل الإعداد لاستخدام الموصل المحلي

استخدم هذا الخيار عندما يحتاج خادم MCP إلى الوصول إلى ملفات محلية أو تطبيقات أو موارد خاصة على جهاز الكمبيوتر لديك.

1

فتح إعدادات MCP

في TypingMind، انتقل إلى «الإعدادات»، ثم «الإعدادات المتقدمة»، ثم «بروتوكول سياق النموذج»، واختر «إعداد الموصل».

  1. افتح TypingMind في متصفحك.
  2. انقر على أيقونة الإعدادات.
  3. انتقل إلى الإعدادات المتقدمة.
  4. افتح قسم بروتوكول سياق النموذج.
  5. انقر على «إعداد الموصل» واختر «هذا الجهاز».
شاشة إعداد موصل MCP في TypingMind مع تحديد «هذا الجهاز»
2

تنفيذ أمر الموصل

اختر «هذا الجهاز»، وانسخ الأمر من TypingMind وشغّله في Terminal. أبقِ العملية قيد التشغيل أثناء استخدام MCP.

  1. انسخ أمر الإعداد الذي يعرضه TypingMind.
  2. افتح Terminal على macOS أو Windows Terminal على Windows.
  3. الصق الأمر ونفّذه.
  4. وافق على تثبيت الحزمة إذا طلب منك Terminal تأكيد المتابعة.
  5. أبقِ نافذة Terminal والعملية التي تعمل فيها قيد التشغيل أثناء استخدام أدوات MCP.
3

أضف Lambda MCP Server كخادم

عندما تظهر حالة الموصل «جاهز»، انقر على «تعديل الخوادم» والصق إعدادات خادم MCP.

  1. انتظر حتى تظهر حالة الموصل «جاهز».
  2. انقر على «تعديل الخوادم».
  3. الصق إعدادات خادم MCP الخاص بـ Lambda MCP Server.
  4. احفظ قائمة الخوادم.
  5. حدّث الحالة إذا أردت التأكد من أن الموصل لا يزال جاهزًا.
إعدادات MCP في TypingMind تعرض خادمًا نشطًا وزر «تعديل الخوادم»
{
  "mcpServers": {
    "lambda-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

استخدام الاتصال مع نماذج مختلفة

احفظ قائمة الخوادم، وافتح «الإضافات»، وفعّل أدوات MCP الخاصة بـ Lambda MCP Server، ثم اختر أي نموذج ذكاء اصطناعي مدعوم في TypingMind واستخدم الأدوات في المحادثة أو أسندها إلى وكيل ذكاء اصطناعي.

  1. افتح صفحة الإضافات في TypingMind.
  2. فعّل أدوات MCP الخاصة بـ Lambda MCP Server.
  3. ابدأ محادثة واختر نموذج الذكاء الاصطناعي الذي تريد استخدامه.
  4. استخدم أدوات MCP في المحادثة أو عيّنها لوكيل ذكاء اصطناعي.
  5. انتقل إلى نموذج ذكاء اصطناعي آخر عند الحاجة دون إعادة الاتصال بـ MCP.
محادثة في TypingMind تستخدم أدوات MCP المفعّلة مع نموذج ذكاء اصطناعي محدّد
هل يمكنك استخدام Lambda MCP Server لمساعدتي في هذه المهمة؟
Lambda MCP Server
بالتأكيد. قرأته.
إليك ما وجدته باستخدام Lambda MCP Server.

الأسئلة الشائعة

ما استخدامات خادم MCP Lambda MCP Server؟

Lambda MCP Server هو خادم MCP يتيح لتطبيقات الذكاء الاصطناعي المتوافقة الاتصال بأدوات ومصادر سياق خارجية. في TypingMind، يمكنك إضافة خادم MCP هذا مرة واحدة وإتاحة أدواته في مساحة عملك للذكاء الاصطناعي.

هل يمكنني استخدام خادم MCP Lambda MCP Server مع نماذج ذكاء اصطناعي متعددة في TypingMind؟

نعم. يربط TypingMind أدوات MCP على مستوى مساحة العمل، لذا يمكنك استخدام Lambda MCP Server مع نماذج ذكاء اصطناعي مختلفة مثل Claude أو ChatGPT أو Gemini أو غيرها من النماذج التي أعددتها في TypingMind، دون إعداد خادم MCP لكل نموذج على حدة.

لماذا تستخدم موصل MCP Lambda MCP Server مع TypingMind؟

يُعد TypingMind من أفضل واجهات المحادثة مع النماذج اللغوية الكبيرة، إذ يجمع نماذج ذكاء اصطناعي متعددة ومطالبات وإضافات ووكلاء ذكاء اصطناعي ومفاتيح API وأدوات MCP في مساحة عمل واحدة. بعد توصيل Lambda MCP Server، يمكنك استخدام أدوات MCP الخاصة به عبر نماذجك المفضلة مع الحفاظ على سير عمل محادثاتك منظمًا في TypingMind.

كيف أوصّل خادم MCP Lambda MCP Server بـ TypingMind؟

يعمل Lambda MCP Server عبر موصل MCP المحلي في TypingMind. هذا هو الخيار الأنسب عندما يحتاج خادم MCP إلى الوصول إلى ملفات محلية أو تطبيقات سطح المكتب أو أدوات سطر الأوامر أو موارد خاصة على حاسوبك.

ما الأدوات التي يوفّرها خادم MCP Lambda MCP Server في TypingMind؟

يتيح Lambda MCP Server إمكانات MCP يمكنك تفعيلها من صفحة الإضافات في TypingMind واستخدامها في المحادثات أو تعيينها لوكلاء ذكاء اصطناعي.

هل أحتاج إلى مشاركة مفاتيح API الخاصة بي مع TypingMind لاستخدام خادم MCP Lambda MCP Server؟

لا. يعطي TypingMind الأولوية للعمل المحلي ويُبقي مزوّدي النماذج ومفاتيح API والمطالبات وإعدادات MCP تحت تحكمك. إذا كان Lambda MCP Server يتطلب مصادقة، فأضف الترويسات أو إعدادات OAuth أو الإعدادات المحلية المطلوبة لخادم MCP هذا عند إنشاء الاتصال.

خوادم MCP ذات صلة

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا البريدية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇