MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / runMcpHttpBridge

Function runMcpHttpBridge

apps/cli/src/main.ts:1397–1486  ·  view source on GitHub ↗
(input: {
  readonly manifest: ExecutorLocalServerManifest;
  readonly elicitationMode: "browser" | "model";
  readonly artifacts: boolean;
  readonly searchTools: boolean;
  readonly toolMode: "codemode" | "passthrough";
})

Source from the content-addressed store, hash-verified

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

Callers 1

runStdioMcpSessionFunction · 0.85

Calls 8

reportErrorFunction · 0.85
forwardMessageFunction · 0.85
closeBothFunction · 0.85
finishFunction · 0.70
sendMethod · 0.65
startMethod · 0.65

Tested by

no test coverage detected