1
- # Utilities for Model Context Protocol (MCP) with AWS Lambda
1
+ # Run Model Context Protocol (MCP) servers in AWS Lambda
2
2
3
- This project enables you to run [ Model Context Protocol] ( https://modelcontextprotocol.io ) servers in AWS Lambda functions.
3
+ This project enables you to run [ Model Context Protocol] ( https://modelcontextprotocol.io ) stdio-based servers in AWS Lambda functions.
4
4
5
5
Currently, most implementations of MCP servers and clients are entirely local on a single machine.
6
6
A desktop application such as an IDE or Claude Desktop initiates MCP servers locally as child processes
@@ -22,7 +22,8 @@ You can invoke these function-based MCP servers from your application using the
22
22
over short-lived connections.
23
23
Your application can then be a desktop-based app, a distributed system running in the cloud,
24
24
or any other architecture.
25
- The only requirement is that your application has access to invoke your Lambda functions.
25
+ Your application must have access to invoke your Lambda functions,
26
+ and use the custom MCP client transport that invokes the Lambda functions.
26
27
27
28
``` mermaid
28
29
flowchart LR
@@ -37,6 +38,12 @@ flowchart LR
37
38
38
39
## Considerations
39
40
41
+ - This package currently requires using a custom MCP client transport to communicate with the MCP
42
+ server by invoking the Lambda function. Existing applications with MCP support such as
43
+ Amazon Q Developer CLI, Cline, etc do not have this custom transport, and cannot communicate with
44
+ MCP servers adapted into Lambda functions.
45
+ Note: with [ upcoming changes to the MCP protocol] ( https://github.com/modelcontextprotocol/specification/pull/206 ) ,
46
+ we expect that this limitation will be removed in the future.
40
47
- This package currently supports MCP servers and clients written in Python and Typescript.
41
48
Other languages such as Kotlin are not supported.
42
49
- The server adapters only adapt stdio MCP servers, not servers written for other protocols such as SSE.
@@ -176,112 +183,7 @@ await this.client.connect(transport);
176
183
177
184
### Deploy and run the examples
178
185
179
- First, install the [ AWS CDK CLI] ( https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_install ) .
180
-
181
- Request [ Bedrock model access] ( https://us-west-2.console.aws.amazon.com/bedrock/home?region=us-west-2#/modelaccess )
182
- to Anthropic Claude 3.5 Sonnet v2 in region us-west-2.
183
-
184
- Install the mcp-lambda Python module from source:
185
-
186
- ``` bash
187
- cd src/python/
188
-
189
- uv venv
190
- source .venv/bin/activate
191
-
192
- uv sync --all-extras --dev
193
-
194
- # For development
195
- uv run ruff check .
196
- uv run pyright
197
- uv run pytest
198
- ```
199
-
200
- Create an IAM role for the example Lambda functions and bootstrap the account for CDK:
201
-
202
- ``` bash
203
- aws iam create-role \
204
- --role-name mcp-lambda-example-servers \
205
- --assume-role-policy-document file://examples/servers/lambda-assume-role-policy.json
206
-
207
- aws iam attach-role-policy \
208
- --role-name mcp-lambda-example-servers \
209
- --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
210
-
211
- cdk bootstrap aws://< aws account id> /us-east-2
212
- ```
213
-
214
- Deploy the Lambda 'time' function - the deployed function will be named "mcp-server-time".
215
-
216
- ``` bash
217
- cd examples/servers/time/
218
-
219
- uv pip install -r requirements.txt
220
-
221
- cdk deploy --app ' python3 cdk_stack.py'
222
- ```
223
-
224
- Build the mcp-lambda Typescript module:
225
-
226
- ``` bash
227
- cd src/typescript/
228
-
229
- npm install
230
-
231
- npm run build
232
-
233
- npm link
234
- ```
235
-
236
- Deploy the Lambda 'weather-alerts' function - the deployed function will be named "mcp-server-weather-alerts".
237
-
238
- ``` bash
239
- cd examples/servers/weather-alerts/
240
-
241
- npm install
242
-
243
- npm link mcp-lambda
244
-
245
- npm run build
246
-
247
- cdk deploy --app ' node lib/weather-alerts-mcp-server.js'
248
- ```
249
-
250
- Run the Python-based chatbot client:
251
-
252
- ``` bash
253
- cd examples/chatbots/python/
254
-
255
- uv pip install -r requirements.txt
256
-
257
- python main.py
258
- ```
259
-
260
- Alternatively, run the Typescript-based chatbot client:
261
-
262
- ``` bash
263
- cd examples/chatbots/typescript/
264
-
265
- npm install
266
-
267
- npm link mcp-lambda
268
-
269
- npm run build
270
-
271
- npm run start
272
- ```
273
-
274
- The chatbot client will communicate with three servers:
275
-
276
- 1 . the Lambda function-based 'time' MCP server
277
- 2 . the Lambda function-based 'weather-alerts' MCP server
278
- 3 . a [ local 'fetch' MCP server] ( https://github.com/modelcontextprotocol/servers/tree/main/src/fetch )
279
-
280
- To use the remote 'time' server, you can ask the chatbot questions like "What is the current time?".
281
-
282
- To use the remote 'weather-alerts' server, you can ask the chatbot questions like "Are there any weather alerts right now?".
283
-
284
- To use the local 'fetch' server, you can ask questions like "Who is Tom Cruise?".
186
+ See the [ development guide] ( DEVELOP.md ) for instructions to deploy and run the examples in this repository.
285
187
286
188
## Security
287
189
0 commit comments