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