@ttoss/http-server-mcp 0.16.3 → 0.16.5

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.
Files changed (2) hide show
  1. package/README.md +48 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -634,11 +634,58 @@ This package implements the [Model Context Protocol](https://spec.modelcontextpr
634
634
  - `Content-Type: application/json`
635
635
  - `Accept: application/json, text/event-stream`
636
636
 
637
- **Stateless vs stateful mode:**
637
+ ### Stateless vs stateful mode
638
638
 
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",
3
+ "version": "0.16.5",
4
4
  "description": "Model Context Protocol (MCP) server integration for @ttoss/http-server",
5
5
  "keywords": [
6
6
  "ai",