Skip to content

Commit 4e7eb6b

Browse files
committed
chore(docs): Add three architecture diagrams
1 parent 0ca317b commit 4e7eb6b

File tree

1 file changed

+93
-43
lines changed

1 file changed

+93
-43
lines changed

README.md

Lines changed: 93 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,62 +17,65 @@ flowchart LR
1717
end
1818
```
1919

20-
This MCP server adapter for AWS Lambda helps you to wrap existing stdio MCP servers into Lambda functions.
20+
This library helps you to wrap existing stdio MCP servers into Lambda functions.
2121
You can invoke these function-based MCP servers from your application using the MCP protocol
22-
over short-lived connections.
22+
over short-lived HTTPS connections.
2323
Your application can then be a desktop-based app, a distributed system running in the cloud,
2424
or any other architecture.
25-
Your application must have access to invoke your Lambda functions,
26-
and use the custom MCP client transport that invokes the Lambda functions.
2725

2826
```mermaid
2927
flowchart LR
3028
subgraph "Distributed System"
3129
App["Your Application<br>with MCP Clients"]
3230
S3["MCP Server A<br>(Lambda function)"]
3331
S4["MCP Server B<br>(Lambda function)"]
34-
App <-->|"MCP Protocol<br>with custom transport<br>(invoke function)"| S3
35-
App <-->|"MCP Protocol<br>with custom transport<br>(invoke function)"| S4
32+
App <-->|"MCP Protocol<br>(over HTTPS connection)"| S3
33+
App <-->|"MCP Protocol<br>(over HTTPS connection)"| S4
3634
end
3735
```
3836

39-
## Considerations
37+
This library supports connecting to Lambda-based MCP servers in three ways:
4038

41-
- If you are looking for a way to invoke existing Lambda functions as tools through MCP,
42-
see the [AWS Lambda MCP Server project](https://awslabs.github.io/mcp/servers/lambda-mcp-server/).
43-
- This package currently requires using a custom MCP client transport to communicate with the MCP
44-
server by invoking the Lambda function. Existing applications with MCP support such as
45-
Amazon Q Developer CLI, Cline, etc do not have this custom transport, and cannot communicate with
46-
MCP servers adapted into Lambda functions.
47-
Note: with [upcoming changes to the MCP protocol](https://github.com/modelcontextprotocol/specification/pull/206),
48-
we expect that this limitation will be removed in the future.
49-
- This package currently supports MCP servers and clients written in Python and Typescript.
50-
Other languages such as Kotlin are not supported.
51-
- The server adapters only adapt stdio MCP servers, not servers written for other protocols such as SSE.
52-
- The server adapters do not maintain any MCP server state across Lambda function invocations.
53-
Only stateless MCP servers are a good fit for using this adapter. For example, MCP servers
54-
that invoke stateless tools like the [time MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/time)
55-
or make stateless web requests like the [fetch MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/fetch).
56-
Stateful MCP servers are not a good fit, because they will lose their state on every request.
57-
For example, MCP servers that manage data on disk or in memory such as
58-
the [sqlite MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/sqlite),
59-
the [filesystem MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem),
60-
and the [git MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/git).
61-
- The server adapters ignore any MCP protocol notifications from the client to the server.
62-
- The server adapters do not provide mechanisms for managing any secrets needed by the wrapped
63-
MCP server. For example, the [GitHub MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/github)
64-
and the [Brave search MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/brave-search)
65-
require API keys to make requests to third-party APIs.
66-
You can configure these API keys as
67-
[encrypted environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars-encryption.html)
68-
in the Lambda function's configuration. However, note that anyone with access to invoke the Lambda function
69-
will then have access to use your API key to call the third-party APIs by invoking the function.
70-
We recommend limiting access to the Lambda function using
71-
[least-privilege IAM policies](https://docs.aws.amazon.com/lambda/latest/dg/security-iam.html).
39+
1. The [MCP Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http), using Amazon API Gateway. Typically authenticated using OAuth.
40+
2. A custom Streamable HTTP transport with support for SigV4, using a Lambda function URL. Authenticated with AWS IAM.
41+
3. A custom Lambda invocation transport, using the Lambda Invoke API directly. Authenticated with AWS IAM.
42+
43+
## Using API Gateway
44+
45+
```mermaid
46+
flowchart LR
47+
App["MCP Client"]
48+
T1["MCP Server<br>(Lambda function)"]
49+
T2["API Gateway"]
50+
T3["OAuth Server<br>(Cognito or similar)"]
51+
App -->|"MCP Streamable<br>HTTP Transport"| T2
52+
T2 -->|"Invoke"| T1
53+
T2 -->|"Authorize"| T3
54+
```
55+
56+
## Using a Lambda function URL
57+
58+
```mermaid
59+
flowchart LR
60+
App["MCP Client"]
61+
T1["MCP Server<br>(Lambda function)"]
62+
T2["Lambda function URL"]
63+
App -->|"Custom Streamable HTTP<br>Transport with AWS Auth"| T2
64+
T2 -->|"Invoke"| T1
65+
```
66+
67+
## Using the Lambda Invoke API
68+
69+
```mermaid
70+
flowchart LR
71+
App["MCP Client"]
72+
T1["MCP Server<br>(Lambda function)"]
73+
App -->|"Custom MCP Transport<br>(Lambda Invoke API)"| T1
74+
```
7275

73-
## Examples
76+
<details>
7477

75-
### Python server example
78+
<summary><b>Python server example</b></summary>
7679

7780
This project includes an
7881
[example Python Lambda function](examples/servers/time/function/index.py)
@@ -108,7 +111,11 @@ def handler(event, context):
108111
return stdio_server_adapter(server_params, event, context)
109112
```
110113

111-
### Typescript server example
114+
</details>
115+
116+
<details>
117+
118+
<summary><b>Typescript server example</b></summary>
112119

113120
This project includes an
114121
[example Node.js Lambda function](examples/servers/weather-alerts/lib/weather-alerts-mcp-server.function.ts)
@@ -142,7 +149,11 @@ export const handler: Handler = async (event, context: Context) => {
142149
};
143150
```
144151

145-
### Python client example
152+
</details>
153+
154+
<details>
155+
156+
<summary><b>Python client example</b></summary>
146157

147158
This project includes an
148159
[example Python MCP client](examples/chatbots/python/server_clients/lambda_function.py)
@@ -164,7 +175,11 @@ session = ClientSession(read, write)
164175
await session.initialize()
165176
```
166177

167-
### Typescript client example
178+
</details>
179+
180+
<details>
181+
182+
<summary><b>Typescript client example</b></summary>
168183

169184
This project includes an
170185
[example Typescript MCP client](examples/chatbots/typescript/src/server_clients/lambda_function.ts)
@@ -200,6 +215,41 @@ const transport = new LambdaFunctionClientTransport(serverParams);
200215
await client.connect(transport);
201216
```
202217

218+
</details>
219+
220+
## Related projects
221+
222+
- To write custom MCP servers in Lambda functions,
223+
see the [MCP Lambda Handler](https://github.com/awslabs/mcp/tree/main/src/mcp-lambda-handler) project.
224+
- To invoke existing Lambda functions as tools through a stdio MCP server,
225+
see the [AWS Lambda Tool MCP Server](https://awslabs.github.io/mcp/servers/lambda-tool-mcp-server/) project.
226+
227+
## Considerations
228+
229+
- This library currently supports MCP servers and clients written in Python and Typescript.
230+
Other languages such as Kotlin are not supported.
231+
- This library only adapts stdio MCP servers for Lambda, not servers written for other protocols such as SSE.
232+
- This library does not maintain any MCP server state or sessions across Lambda function invocations.
233+
Only stateless MCP servers are a good fit for using this adapter. For example, MCP servers
234+
that invoke stateless tools like the [time MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/time)
235+
or make stateless web requests like the [fetch MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/fetch).
236+
Stateful MCP servers are not a good fit, because they will lose their state on every request.
237+
For example, MCP servers that manage data on disk or in memory such as
238+
the [sqlite MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/sqlite),
239+
the [filesystem MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem),
240+
and the [git MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/git).
241+
- The server adapters do not provide mechanisms for managing any secrets needed by the wrapped
242+
MCP server. For example, the [GitHub MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/github)
243+
and the [Brave search MCP server](https://github.com/modelcontextprotocol/servers/tree/main/src/brave-search)
244+
require API keys to make requests to third-party APIs.
245+
You can configure these API keys as
246+
[encrypted environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars-encryption.html)
247+
in the Lambda function's configuration. However, note that anyone with access to invoke the Lambda function
248+
will then have access to use your API key to call the third-party APIs by invoking the function.
249+
We recommend limiting access to the Lambda function using
250+
[least-privilege IAM policies](https://docs.aws.amazon.com/lambda/latest/dg/security-iam.html).
251+
If you use an identity-based authentication mechanism such as OAuth, you could also store and retrieve API keys per user but there are no implementation examples in this repository.
252+
203253
### Deploy and run the examples
204254

205255
See the [development guide](DEVELOP.md) for instructions to deploy and run the examples in this repository.

0 commit comments

Comments
 (0)