(executor: Executor)
| 105 | }; |
| 106 | |
| 107 | const makeMcpFetch = (executor: Executor) => { |
| 108 | const engine = createExecutionEngine({ |
| 109 | executor, |
| 110 | codeExecutor: makeQuickJsExecutor(), |
| 111 | }); |
| 112 | const mcp = createMcpRequestHandler({ engine }); |
| 113 | |
| 114 | const fetchImpl: typeof globalThis.fetch = Object.assign( |
| 115 | (input: RequestInfo | URL, init?: RequestInit) => { |
| 116 | const request = input instanceof Request ? input : new Request(input, init); |
| 117 | const url = new URL(request.url); |
| 118 | if (url.pathname.startsWith("/mcp")) return mcp.handleRequest(request); |
| 119 | if (url.pathname.startsWith("/api/mcp-sessions/")) { |
| 120 | return mcp.handleApprovalRequest(request); |
| 121 | } |
| 122 | return Promise.resolve(new Response("Not found", { status: 404 })); |
| 123 | }, |
| 124 | { preconnect: globalThis.fetch.preconnect }, |
| 125 | ); |
| 126 | |
| 127 | return { fetch: fetchImpl, dispose: mcp.close }; |
| 128 | }; |
| 129 | |
| 130 | const readStructuredRecord = (value: unknown): Record<string, unknown> => { |
| 131 | expect(typeof value).toBe("object"); |
no test coverage detected