(input: {
readonly manifest: ExecutorLocalServerManifest;
readonly elicitationMode: "browser" | "model";
readonly artifacts: boolean;
})
| 1382 | * when stdin closes or the daemon connection drops; close is best-effort. |
| 1383 | */ |
| 1384 | const runMcpHttpBridge = async (input: { |
| 1385 | readonly manifest: ExecutorLocalServerManifest; |
| 1386 | readonly elicitationMode: "browser" | "model"; |
| 1387 | readonly artifacts: boolean; |
| 1388 | }): Promise<void> => { |
| 1389 | const stdio = new StdioServerTransport(); |
| 1390 | const authorization = getExecutorServerAuthorizationHeader(input.manifest.connection); |
| 1391 | const http = new StreamableHTTPClientTransport( |
| 1392 | mcpUrlForActiveLocalServer({ |
| 1393 | connection: input.manifest.connection, |
| 1394 | elicitationMode: input.elicitationMode, |
| 1395 | artifacts: input.artifacts, |
| 1396 | }), |
| 1397 | authorization ? { requestInit: { headers: { Authorization: authorization } } } : undefined, |
| 1398 | ); |
| 1399 | |
| 1400 | let finished = false; |
| 1401 | let closing = false; |
| 1402 | let closePromise: Promise<void> | null = null; |
| 1403 | let resolveExit: () => void = () => {}; |
| 1404 | const waitForExit = new Promise<void>((resolve) => { |
| 1405 | resolveExit = resolve; |
| 1406 | }); |
| 1407 | |
| 1408 | const finish = () => { |
| 1409 | if (finished) return; |
| 1410 | finished = true; |
| 1411 | process.off("SIGINT", shutdown); |
| 1412 | process.off("SIGTERM", shutdown); |
| 1413 | process.stdin.off("end", shutdown); |
| 1414 | process.stdin.off("close", shutdown); |
| 1415 | resolveExit(); |
| 1416 | }; |
| 1417 | |
| 1418 | const closeBoth = (): Promise<void> => { |
| 1419 | if (!closePromise) { |
| 1420 | closing = true; |
| 1421 | closePromise = Promise.allSettled([stdio.close(), http.close()]).then(() => undefined); |
| 1422 | } |
| 1423 | return closePromise; |
| 1424 | }; |
| 1425 | |
| 1426 | function shutdown() { |
| 1427 | finish(); |
| 1428 | void closeBoth(); |
| 1429 | } |
| 1430 | |
| 1431 | const isAbortDuringClose = (error: Error): boolean => |
| 1432 | error.name === "AbortError" || error.message.toLowerCase().includes("aborted"); |
| 1433 | |
| 1434 | const reportError = (context: string, cause: unknown) => { |
| 1435 | const error = toError(cause); |
| 1436 | if (closing && isAbortDuringClose(error)) return; |
| 1437 | console.error(`Executor MCP bridge ${context}: ${error.message}`); |
| 1438 | }; |
| 1439 | |
| 1440 | const forwardMessage = |
| 1441 | (send: (message: JSONRPCMessage) => Promise<void>, context: string) => |
no test coverage detected