@ttoss/http-server-mcp 0.16.3 → 0.16.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -639,6 +639,53 @@ This package implements the [Model Context Protocol](https://spec.modelcontextpr
|
|
|
639
639
|
- **Stateless** (default, `sessionIdGenerator: undefined`) — a fresh transport is created per HTTP request. No session tracking. Suitable for serverless environments and simple integrations.
|
|
640
640
|
- **Stateful** (`sessionIdGenerator` provided) — a single shared transport handles all requests and tracks sessions by ID.
|
|
641
641
|
|
|
642
|
+
## AWS Lambda Deployment
|
|
643
|
+
|
|
644
|
+
The default **stateless** mode (see [Stateless vs stateful mode](#stateless-vs-stateful-mode)) is built for serverless: a fresh transport is created per request, nothing is kept in memory between invocations, and responses are plain JSON (no SSE) — exactly the request/response shape API Gateway and Lambda Function URLs expect. Because the router is a regular Koa app, you wrap it with any Koa-to-Lambda adapter (e.g. [`serverless-http`](https://github.com/dougmoscrop/serverless-http)) and front it with an HTTP API Gateway or a Function URL.
|
|
645
|
+
|
|
646
|
+
```mermaid
|
|
647
|
+
flowchart LR
|
|
648
|
+
Client[MCP Client] -->|POST /mcp| GW[API Gateway / Function URL]
|
|
649
|
+
GW --> L[Lambda]
|
|
650
|
+
subgraph L[Lambda]
|
|
651
|
+
H[serverless-http handler] --> App[Koa App + createMcpRouter]
|
|
652
|
+
end
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
```typescript
|
|
656
|
+
import serverless from 'serverless-http';
|
|
657
|
+
import { App, bodyParser } from '@ttoss/http-server';
|
|
658
|
+
import { createMcpRouter, McpServer, z } from '@ttoss/http-server-mcp';
|
|
659
|
+
|
|
660
|
+
const mcpServer = new McpServer({ name: 'my-mcp-server', version: '1.0.0' });
|
|
661
|
+
|
|
662
|
+
mcpServer.registerTool(
|
|
663
|
+
'get-weather',
|
|
664
|
+
{
|
|
665
|
+
description: 'Get weather for a location',
|
|
666
|
+
inputSchema: { location: z.string() },
|
|
667
|
+
},
|
|
668
|
+
async ({ location }) => ({
|
|
669
|
+
content: [{ type: 'text', text: `Weather in ${location}: Sunny` }],
|
|
670
|
+
})
|
|
671
|
+
);
|
|
672
|
+
|
|
673
|
+
const app = new App();
|
|
674
|
+
app.use(bodyParser());
|
|
675
|
+
// Stateless by default — no sessionIdGenerator
|
|
676
|
+
app.use(createMcpRouter(mcpServer).routes());
|
|
677
|
+
|
|
678
|
+
export const handler = serverless(app.callback());
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
Keep the following in mind:
|
|
682
|
+
|
|
683
|
+
- **Do not pass `sessionIdGenerator`.** Stateful mode relies on a shared in-memory transport that does not survive across Lambda containers; each invocation may land on a different one.
|
|
684
|
+
- **Authentication** via the [`auth`](#authentication) option (Cognito or a custom `verifyToken`) runs inside the handler and pairs naturally with API Gateway — you can also delegate to a Gateway authorizer.
|
|
685
|
+
- **SSE streaming is not used** (`enableJsonResponse: true`), so a standard API Gateway integration is enough; Function URL response streaming is not required.
|
|
686
|
+
|
|
687
|
+
> This differs from [`awslabs/run-model-context-protocol-servers-with-aws-lambda`](https://github.com/awslabs/run-model-context-protocol-servers-with-aws-lambda), which wraps **stdio**-based MCP servers into Lambda by spawning a child process per invocation. `@ttoss/http-server-mcp` already speaks Streamable HTTP, so that wrapper is unnecessary — you deploy it like any other HTTP handler.
|
|
688
|
+
|
|
642
689
|
## Related Packages
|
|
643
690
|
|
|
644
691
|
- [@ttoss/http-server](https://ttoss.dev/docs/modules/packages/http-server) - HTTP server foundation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/http-server-mcp",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
4
4
|
"description": "Model Context Protocol (MCP) server integration for @ttoss/http-server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
37
37
|
"zod": "^4.4.3",
|
|
38
|
-
"@ttoss/
|
|
38
|
+
"@ttoss/http-server": "^0.7.1",
|
|
39
39
|
"@ttoss/http-server-auth": "^0.3.3",
|
|
40
|
-
"@ttoss/
|
|
40
|
+
"@ttoss/auth-core": "^0.7.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/koa": "^3.0.3",
|