Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
## サポート対象バージョン

本プロジェクト(aws-lambda-mcp-server)は現在アクティブに開発されています。
セキュリティアップデートは最新版(0.x.x系)のみ提供しています。
セキュリティアップデートは最新版(2.x.x系)のみ提供しています。

| バージョン | サポート状況 |
| ---------- | ------------------- |
| 0.x.x | ✅ |
| 2.x.x | ✅ |

## セキュリティに関するご注意

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,4 @@ vite.config.ts.timestamp-*

# 一時ファイル
pull_request.md
github_pull_request.md
10 changes: 8 additions & 2 deletions example/lambda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const createMcpServer = () => {
return server;
};
const app = createHonoApp(createMcpServer, {
// host: '0.0.0.0' は認証・認可を無効にする(開発用。本番では適切な認証を設定してください)
host: '0.0.0.0',
});

Expand Down Expand Up @@ -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);
});
}
2 changes: 1 addition & 1 deletion example/lib/example-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);",
},
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 35 additions & 4 deletions package/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const closeResources = async (
*/
const handleRequest = async (
createMcpServer: () => McpServer,
c: Context<Env, '/mcp', BlankInput>,
c: Context<BlankEnv, '/mcp', BlankInput>,
) => {
const transport = new WebStandardStreamableHTTPServerTransport({
sessionIdGenerator: undefined, // セッションIDを生成しない(ステートレスモード)
Expand Down Expand Up @@ -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
Expand All @@ -165,9 +168,37 @@ export const createHonoApp = (
): Hono<Env, BlankSchema, '/'> => {
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;
};
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading