From e0dd33ebf5b016092bb481c8f5e3dd05eb48bc15 Mon Sep 17 00:00:00 2001 From: Clare Liguori Date: Tue, 1 Apr 2025 16:44:21 -0700 Subject: [PATCH 1/2] Rename the module to mcp-server-in-aws-lambda --- .github/workflows/cdk-checks.yml | 4 ++-- .github/workflows/typescript-checks.yml | 4 ++-- DEVELOP.md | 8 +++---- README.md | 23 +++++++++++++++---- e2e_tests/python/requirements.txt | 5 ++-- e2e_tests/run_integ_test.sh | 4 ++-- .../src/server_clients/lambda_function.ts | 2 +- examples/chatbots/python/requirements.txt | 5 ++-- .../src/server_clients/lambda_function.ts | 2 +- .../servers/time/function/requirements.txt | 5 ++-- .../lib/weather-alerts-mcp-server.function.ts | 4 +++- .../lib/weather-alerts-mcp-server.ts | 11 +++++---- src/python/pyproject.toml | 2 +- src/python/uv.lock | 2 +- src/typescript/package.json | 2 +- 15 files changed, 53 insertions(+), 30 deletions(-) diff --git a/.github/workflows/cdk-checks.yml b/.github/workflows/cdk-checks.yml index f479809..8e40f2c 100644 --- a/.github/workflows/cdk-checks.yml +++ b/.github/workflows/cdk-checks.yml @@ -47,12 +47,12 @@ jobs: - name: Install CDK CLI run: npm install -g aws-cdk - - name: Build and link mcp-lambda package + - name: Build and link mcp-server-in-aws-lambda package run: npm ci && npm run build && npm link working-directory: ./src/typescript - name: Install dependencies - run: npm ci && npm link mcp-lambda + run: npm ci && npm link mcp-server-in-aws-lambda working-directory: ./examples/servers/weather-alerts - name: Build diff --git a/.github/workflows/typescript-checks.yml b/.github/workflows/typescript-checks.yml index 8dacf9a..8b047af 100644 --- a/.github/workflows/typescript-checks.yml +++ b/.github/workflows/typescript-checks.yml @@ -42,12 +42,12 @@ jobs: with: node-version: 20 - - name: Build and link mcp-lambda package + - name: Build and link mcp-server-in-aws-lambda package run: npm ci && npm run build && npm link working-directory: ./src/typescript - name: Install dependencies - run: npm ci && npm link mcp-lambda + run: npm ci && npm link mcp-server-in-aws-lambda working-directory: ./examples/chatbots/typescript - name: Build diff --git a/DEVELOP.md b/DEVELOP.md index 1b887d7..b206552 100644 --- a/DEVELOP.md +++ b/DEVELOP.md @@ -39,7 +39,7 @@ cdk bootstrap aws:///us-east-2 ### Build the Python module -Install the mcp-lambda Python module from source: +Install the mcp-server-in-aws-lambda Python module from source: ```bash cd src/python/ @@ -57,7 +57,7 @@ uv run pytest ### Build the Typescript package -Build the mcp-lambda Typescript module: +Build the mcp-server-in-aws-lambda Typescript module: ```bash cd src/typescript/ @@ -90,7 +90,7 @@ cd examples/servers/weather-alerts/ npm install -npm link mcp-lambda +npm link mcp-server-in-aws-lambda npm run build @@ -118,7 +118,7 @@ cd examples/chatbots/typescript/ npm install -npm link mcp-lambda +npm link mcp-server-in-aws-lambda npm run build diff --git a/README.md b/README.md index 3553138..f2fb393 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ flowchart LR - This package currently supports MCP servers and clients written in Python and Typescript. Other languages such as Kotlin are not supported. - The server adapters only adapt stdio MCP servers, not servers written for other protocols such as SSE. -- The server adapters does not maintain any MCP server state across Lambda function invocations. +- The server adapters do not maintain any MCP server state across Lambda function invocations. Only stateless MCP servers are a good fit for using this adapter. For example, MCP servers that invoke stateless tools like the [time MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/time) or make stateless web requests like the [fetch MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/fetch). @@ -124,7 +124,6 @@ It will: ```typescript import { Handler, Context } from "aws-lambda"; -import { stdioServerAdapter } from "mcp-lambda"; const serverParams = { command: "npx", @@ -132,6 +131,9 @@ const serverParams = { }; export const handler: Handler = async (event, context: Context) => { + // Dynamically import ES module into CommonJS Lambda function + const { stdioServerAdapter } = await import("mcp-server-in-aws-lambda"); + return await stdioServerAdapter(serverParams, event, context); }; ``` @@ -170,15 +172,28 @@ with the MCP protocol and returns the function's response to the caller. import { LambdaFunctionParameters, LambdaFunctionClientTransport, -} from "mcp-lambda"; +} from "mcp-server-in-aws-lambda"; +import { Client } from "@modelcontextprotocol/sdk/client/index.js"; const serverParams: LambdaFunctionParameters = { functionName: "mcp-server-time", regionName: "us-east-2", }; +const client = new Client( + { + name: "my-client", + version: "0.0.1", + }, + { + capabilities: { + sampling: {}, + }, + } +); + const transport = new LambdaFunctionClientTransport(serverParams); -await this.client.connect(transport); +await client.connect(transport); ``` ### Deploy and run the examples diff --git a/e2e_tests/python/requirements.txt b/e2e_tests/python/requirements.txt index 66b3907..75f3ba0 100644 --- a/e2e_tests/python/requirements.txt +++ b/e2e_tests/python/requirements.txt @@ -2,5 +2,6 @@ boto3>=1.36.20,<1.37.24 mcp>=1.6.0 uvicorn>=0.32.1 -# For testing, this module is installed from local files -# mcp-lambda +# For testing, this module is installed from local files. +# Uncomment this line to build using the module from PyPi +# mcp-server-in-aws-lambda >= 0.0.1 diff --git a/e2e_tests/run_integ_test.sh b/e2e_tests/run_integ_test.sh index 531c1c3..7bd09d6 100755 --- a/e2e_tests/run_integ_test.sh +++ b/e2e_tests/run_integ_test.sh @@ -25,7 +25,7 @@ npm link cd ../../examples/servers/weather-alerts/ npm ci -npm link mcp-lambda +npm link mcp-server-in-aws-lambda npm run build cdk deploy --app 'node lib/weather-alerts-mcp-server.js' @@ -42,6 +42,6 @@ python main.py # Run the Typescript integ test cd ../typescript/ npm ci -npm link mcp-lambda +npm link mcp-server-in-aws-lambda npm run build npm test diff --git a/e2e_tests/typescript/src/server_clients/lambda_function.ts b/e2e_tests/typescript/src/server_clients/lambda_function.ts index 1bb762c..e093c45 100644 --- a/e2e_tests/typescript/src/server_clients/lambda_function.ts +++ b/e2e_tests/typescript/src/server_clients/lambda_function.ts @@ -1,7 +1,7 @@ import { LambdaFunctionParameters, LambdaFunctionClientTransport, -} from "mcp-lambda"; +} from "mcp-server-in-aws-lambda"; import { Server } from "./server.js"; import logger from "../logger.js"; diff --git a/examples/chatbots/python/requirements.txt b/examples/chatbots/python/requirements.txt index 66b3907..75f3ba0 100644 --- a/examples/chatbots/python/requirements.txt +++ b/examples/chatbots/python/requirements.txt @@ -2,5 +2,6 @@ boto3>=1.36.20,<1.37.24 mcp>=1.6.0 uvicorn>=0.32.1 -# For testing, this module is installed from local files -# mcp-lambda +# For testing, this module is installed from local files. +# Uncomment this line to build using the module from PyPi +# mcp-server-in-aws-lambda >= 0.0.1 diff --git a/examples/chatbots/typescript/src/server_clients/lambda_function.ts b/examples/chatbots/typescript/src/server_clients/lambda_function.ts index 1bb762c..e093c45 100644 --- a/examples/chatbots/typescript/src/server_clients/lambda_function.ts +++ b/examples/chatbots/typescript/src/server_clients/lambda_function.ts @@ -1,7 +1,7 @@ import { LambdaFunctionParameters, LambdaFunctionClientTransport, -} from "mcp-lambda"; +} from "mcp-server-in-aws-lambda"; import { Server } from "./server.js"; import logger from "../logger.js"; diff --git a/examples/servers/time/function/requirements.txt b/examples/servers/time/function/requirements.txt index 5d87140..a8d4033 100644 --- a/examples/servers/time/function/requirements.txt +++ b/examples/servers/time/function/requirements.txt @@ -1,4 +1,5 @@ mcp-server-time -# For testing, this module is installed from local files -# mcp-lambda +# For testing, this module is installed from local files. +# Uncomment this line to build using the module from PyPi +# mcp-server-in-aws-lambda >= 0.0.1 diff --git a/examples/servers/weather-alerts/lib/weather-alerts-mcp-server.function.ts b/examples/servers/weather-alerts/lib/weather-alerts-mcp-server.function.ts index e964754..860c087 100644 --- a/examples/servers/weather-alerts/lib/weather-alerts-mcp-server.function.ts +++ b/examples/servers/weather-alerts/lib/weather-alerts-mcp-server.function.ts @@ -6,6 +6,8 @@ const serverParams = { }; export const handler: Handler = async (event, context: Context) => { - const { stdioServerAdapter } = await import("mcp-lambda"); + // Dynamically import ES module into CommonJS Lambda function + const { stdioServerAdapter } = await import("mcp-server-in-aws-lambda"); + return await stdioServerAdapter(serverParams, event, context); }; diff --git a/examples/servers/weather-alerts/lib/weather-alerts-mcp-server.ts b/examples/servers/weather-alerts/lib/weather-alerts-mcp-server.ts index 9e55193..bd66112 100644 --- a/examples/servers/weather-alerts/lib/weather-alerts-mcp-server.ts +++ b/examples/servers/weather-alerts/lib/weather-alerts-mcp-server.ts @@ -15,7 +15,8 @@ export class WeatherAlertsMcpServer extends cdk.Stack { ) { super(scope, id, props); - // Package local module as a layer for testing + // For testing, the mcp-server-in-aws-lambda package is bundled from local files. + // Remove this layer if using the mcp-server-in-aws-lambda package from npm. const mcpLambdaLayer = new LayerVersion(this, "McpLambdaLayer", { code: Code.fromAsset(path.join(__dirname, "../../../../src/typescript"), { bundling: { @@ -24,8 +25,8 @@ export class WeatherAlertsMcpServer extends cdk.Stack { "bash", "-c", [ - "mkdir -p /asset-output/nodejs/node_modules/mcp-lambda", - `cp -r /asset-input/* /asset-output/nodejs/node_modules/mcp-lambda/`, + "mkdir -p /asset-output/nodejs/node_modules/mcp-server-in-aws-lambda", + `cp -r /asset-input/* /asset-output/nodejs/node_modules/mcp-server-in-aws-lambda/`, ].join(" && "), ], }, @@ -52,7 +53,9 @@ export class WeatherAlertsMcpServer extends cdk.Stack { layers: [mcpLambdaLayer], bundling: { nodeModules: ["openapi-mcp-server"], - externalModules: ["mcp-lambda"], + // For testing, the mcp-server-in-aws-lambda package is bundled from local files using the Lambda layer above. + // Remove the layer and this externalModules configuration if using the mcp-server-in-aws-lambda package from npm. + externalModules: ["mcp-server-in-aws-lambda"], commandHooks: { beforeBundling(inputDir: string, outputDir: string): string[] { return []; diff --git a/src/python/pyproject.toml b/src/python/pyproject.toml index 311b38e..874aee9 100644 --- a/src/python/pyproject.toml +++ b/src/python/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "mcp-lambda" +name = "mcp-server-in-aws-lambda" dynamic = ["version"] description = "Model Context Protocol SDK for AWS Lambda" requires-python = ">=3.11" diff --git a/src/python/uv.lock b/src/python/uv.lock index b3235f8..27bf39e 100644 --- a/src/python/uv.lock +++ b/src/python/uv.lock @@ -424,7 +424,7 @@ wheels = [ ] [[package]] -name = "mcp-lambda" +name = "mcp-server-in-aws-lambda" source = { editable = "." } dependencies = [ { name = "aiobotocore" }, diff --git a/src/typescript/package.json b/src/typescript/package.json index c15226b..d890085 100644 --- a/src/typescript/package.json +++ b/src/typescript/package.json @@ -1,5 +1,5 @@ { - "name": "mcp-lambda", + "name": "mcp-server-in-aws-lambda", "description": "Model Context Protocol SDK for AWS Lambda", "version": "0.0.2", "type": "module", From 5ea5e17025539004a24cb288ff5392a5030bc3a6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Apr 2025 23:45:57 +0000 Subject: [PATCH 2/2] chore(deps): update boto3 requirement in /e2e_tests/python Updates the requirements on [boto3](https://github.com/boto/boto3) to permit the latest version. - [Release notes](https://github.com/boto/boto3/releases) - [Commits](https://github.com/boto/boto3/compare/1.36.20...1.37.25) --- updated-dependencies: - dependency-name: boto3 dependency-version: 1.37.25 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- e2e_tests/python/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e_tests/python/requirements.txt b/e2e_tests/python/requirements.txt index 75f3ba0..ef74e68 100644 --- a/e2e_tests/python/requirements.txt +++ b/e2e_tests/python/requirements.txt @@ -1,4 +1,4 @@ -boto3>=1.36.20,<1.37.24 +boto3>=1.36.20,<1.37.26 mcp>=1.6.0 uvicorn>=0.32.1