From d5a28b3cc4ea1cb6e099e501143aad90401a47c2 Mon Sep 17 00:00:00 2001 From: Kenji Saito Date: Wed, 25 Nov 2026 00:08:50 +0900 Subject: [PATCH 1/2] =?UTF-8?q?MCP=202026-07-28=20Streamable=20HTTP=20?= =?UTF-8?q?=E6=BA=96=E6=8B=A0=E3=81=A8=20Lambda=20=E9=96=A2=E6=95=B0=20URL?= =?UTF-8?q?=20=E5=AF=BE=E5=BF=9C=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - package/src/index.ts: - POST /mcp のみをMCPエンドポイントとしてサポート(MCP 2026-07-28 準拠) - OPTIONS /mcp を CORS プリフライト応答として200を返す(Lambda 関数 URL 対応) - GET/DELETE/PUT その他は 405 Method Not Allowed + Allow: POST ヘッダー - JSDoc のタイポ修正、コンテキスト型の統一 - example/lambda/index.ts: - host: '0.0.0.0' にセキュリティ警告コメント追加 - エラーログへの Error オブジェクト直接出力を回避(機密情報漏洩防止) - example/lib/example-stack.ts: - CDK bundling target を node24 から node26 に統一 - .github/SECURITY.md: - サポートバージョン表記を 0.x.x から 2.x.x に更新 --- .github/SECURITY.md | 4 ++-- example/lambda/index.ts | 10 +++++++-- example/lib/example-stack.ts | 2 +- package/src/index.ts | 39 ++++++++++++++++++++++++++++++++---- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/.github/SECURITY.md b/.github/SECURITY.md index 773c1ab..bcd2fe5 100644 --- a/.github/SECURITY.md +++ b/.github/SECURITY.md @@ -3,11 +3,11 @@ ## サポート対象バージョン 本プロジェクト(aws-lambda-mcp-server)は現在アクティブに開発されています。 -セキュリティアップデートは最新版(0.x.x系)のみ提供しています。 +セキュリティアップデートは最新版(2.x.x系)のみ提供しています。 | バージョン | サポート状況 | | ---------- | ------------------- | -| 0.x.x | ✅ | +| 2.x.x | ✅ | ## セキュリティに関するご注意 diff --git a/example/lambda/index.ts b/example/lambda/index.ts index 4e01f6e..7631bd0 100644 --- a/example/lambda/index.ts +++ b/example/lambda/index.ts @@ -30,6 +30,7 @@ const createMcpServer = () => { return server; }; const app = createHonoApp(createMcpServer, { + // host: '0.0.0.0' は認証・認可を無効にする(開発用。本番では適切な認証を設定してください) host: '0.0.0.0', }); @@ -85,12 +86,17 @@ if (!process.env.AWS_LAMBDA_FUNCTION_NAME) { process.on('SIGINT', shutdown); process.on('SIGTERM', shutdown); } catch (error) { - logger.error('サーバーのセットアップに失敗しました:', { error }); + logger.error('サーバーのセットアップに失敗しました:', { + error: + error instanceof Error ? { name: error.name, message: error.message } : String(error), + }); process.exit(1); } }; main().catch((err) => { - logger.error('error', { error: err }); + logger.error('error', { + error: err instanceof Error ? { name: err.name, message: err.message } : String(err), + }); process.exit(1); }); } diff --git a/example/lib/example-stack.ts b/example/lib/example-stack.ts index 1290936..72b2770 100644 --- a/example/lib/example-stack.ts +++ b/example/lib/example-stack.ts @@ -46,7 +46,7 @@ export class ExampleStack extends cdk.Stack { sourceMap: true, // ソースマップを有効化(デバッグ用) keepNames: true, format: cdk.aws_lambda_nodejs.OutputFormat.ESM, - target: 'node24', // Target Node.js 24.x + target: 'node26', // Target Node.js 26.x banner: "import { createRequire } from 'module';const require = createRequire(import.meta.url);", }, diff --git a/package/src/index.ts b/package/src/index.ts index 0d42376..061175c 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -109,7 +109,7 @@ const closeResources = async ( */ const handleRequest = async ( createMcpServer: () => McpServer, - c: Context, + c: Context, ) => { const transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: undefined, // セッションIDを生成しない(ステートレスモード) @@ -144,10 +144,13 @@ const handleRequest = async ( * Honoアプリケーションを生成し、/mcpエンドポイントでMCPサーバーを提供します。 * * @remarks - * POST/GET /mcp でMCPリクエストを受け付け、他のHTTPメソッドは405を返します。 + * POST /mcp でMCPリクエストを受け付けます(MCP 2026-07-28 Streamable HTTP)。 + * OPTIONS /mcp は CORS プリフライト応答として 200 を返します(Lambda 関数 URL 等での利用を想定)。 + * その他のHTTPメソッド(GET、DELETE、PUT など)はすべて 405 Method Not Allowed を返し、 + * Allow ヘッダーに POST を設定します。 * * @param createMcpServer MCPサーバーインスタンスを生成するファクトリ関数 - * @param options `@modelcontextprotocol/hono` パッケージの `createMcpHonoApp()` 関数に関数に渡す options + * @param options `@modelcontextprotocol/hono` パッケージの `createMcpHonoApp()` 関数に渡す options * @returns Honoアプリケーションインスタンス * * @example @@ -165,9 +168,37 @@ export const createHonoApp = ( ): Hono => { const app = createMcpHonoApp(options); - app.all('/mcp', async (c) => { + // MCP メッセージエンドポイント(POST のみ。MCP 2026-07-28 Streamable HTTP 準拠) + app.post('/mcp', async (c) => { return await handleRequest(createMcpServer, c); }); + // CORS プリフライト(OPTIONS のみ。Lambda 関数 URL 等での利用を想定) + app.options('/mcp', (c) => { + return c.json({ message: 'OK' }, 200, { + Allow: 'POST', + }); + }); + + // その他のHTTPメソッドはすべて 405 Method Not Allowed + app.all('/mcp', (c) => { + return c.json( + { + jsonrpc: '2.0', + error: { + code: -32600, + message: 'Method Not Allowed', + }, + id: null, + }, + { + status: 405, + headers: { + Allow: 'POST', + }, + }, + ); + }); + return app; }; From 458ed3f67013c360dca6b5d4a4043807727495b6 Mon Sep 17 00:00:00 2001 From: Kenji Saito Date: Wed, 25 Nov 2026 00:10:33 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BE=9D=E5=AD=98=E3=83=91=E3=83=83?= =?UTF-8?q?=E3=82=B1=E3=83=BC=E3=82=B8=E3=81=AE=E3=82=A2=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + example/package.json | 2 +- pnpm-lock.yaml | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b4eef25..a36d2db 100644 --- a/.gitignore +++ b/.gitignore @@ -142,3 +142,4 @@ vite.config.ts.timestamp-* # 一時ファイル pull_request.md +github_pull_request.md diff --git a/example/package.json b/example/package.json index 74d25a6..ef6c7ea 100644 --- a/example/package.json +++ b/example/package.json @@ -25,7 +25,7 @@ "zod": "4.6.7" }, "devDependencies": { - "@hono/node-server": "2.1.8", + "@hono/node-server": "2.1.9", "@types/aws-lambda": "8.10.164", "@types/node": "26.6.6", "aws-cdk": "2.1148.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5b6d7ef..e1e2147 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -217,8 +217,8 @@ importers: version: 4.6.7 devDependencies: '@hono/node-server': - specifier: 2.1.8 - version: 2.1.8(hono@4.13.19) + specifier: 2.1.9 + version: 2.1.9(hono@4.13.19) '@types/aws-lambda': specifier: 8.10.164 version: 8.10.164 @@ -529,8 +529,8 @@ packages: cpu: [x64] os: [win32] - '@hono/node-server@2.1.8': - resolution: {integrity: sha512-jdf7FHh6A1lzjpHHQUgxsg2GeER2vMetnAOfeActzcoli6jamlK+NAwL6Dsr5Fl3BS3tYUQzCdtZjU8Qxv7bEA==} + '@hono/node-server@2.1.9': + resolution: {integrity: sha512-Sk4NQd3GFY0WZWCzndwFMPwJhtD0y9qjsQ+pjID0/03nK9pxyBCUoUHCho8QYBLBVhi0ssL8UkNPHqbgSOFPIQ==} engines: {node: '>=20'} peerDependencies: hono: ^4 || ^5.0.0-0 @@ -1324,7 +1324,7 @@ snapshots: '@esbuild/win32-x64@0.28.2': optional: true - '@hono/node-server@2.1.8(hono@4.13.19)': + '@hono/node-server@2.1.9(hono@4.13.19)': dependencies: hono: 4.13.19