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/.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/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/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/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; }; 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