import denoJson from "../../../deno.json" with { type: "json" }; import type { ServerModule } from "../types.ts"; import { createMcpConfigStore } from "./config-store.ts"; import { registerMcpRoutes } from "./routes.ts"; import { McpSessionTable } from "./sessions.ts"; /** * AG-1 对外 MCP 服务端(REQ R13、§12.3):/mcp 走 Streamable HTTP,API Key 鉴权, * 每个工具对应一个能力,调用走同一个 registry.invoke(不绕过授权);另提供能力统计、能力清单与 MCP 状态/配置。 * 会话表在进程内(api / all 角色),停机时全部关闭。 */ export function createMcpModule(opts: { version?: string } = {}): ServerModule & { sessions: McpSessionTable } { const table = new McpSessionTable(); return { name: "mcp", sessions: table, registerRoutes(app, ctx) { registerMcpRoutes(app, ctx, { table, config: createMcpConfigStore(() => ctx.db), version: opts.version ?? denoJson.version, }); }, registerTasks() {}, async stop() { await table.closeAll(); }, }; } export const mcpModule = createMcpModule();