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

Function runMcpHttpBridge

apps/cli/src/main.ts:1365–1450  ·  view source on GitHub ↗
(input: {
  readonly manifest: ExecutorLocalServerManifest;
  readonly elicitationMode: "browser" | "model";
  readonly artifacts: boolean;
})

Source from the content-addressed store, hash-verified

1363 * when stdin closes or the daemon connection drops; close is best-effort.
1364 */
1365const runMcpHttpBridge = async (input: {
1366 readonly manifest: ExecutorLocalServerManifest;
1367 readonly elicitationMode: "browser" | "model";
1368 readonly artifacts: boolean;
1369}): Promise<void> => {
1370 const stdio = new StdioServerTransport();
1371 const authorization = getExecutorServerAuthorizationHeader(input.manifest.connection);
1372 const http = new StreamableHTTPClientTransport(
1373 mcpUrlForActiveLocalServer({
1374 connection: input.manifest.connection,
1375 elicitationMode: input.elicitationMode,
1376 artifacts: input.artifacts,
1377 }),
1378 authorization ? { requestInit: { headers: { Authorization: authorization } } } : undefined,
1379 );
1380
1381 let finished = false;
1382 let closing = false;
1383 let closePromise: Promise<void> | null = null;
1384 let resolveExit: () => void = () => {};
1385 const waitForExit = new Promise<void>((resolve) => {
1386 resolveExit = resolve;
1387 });
1388
1389 const finish = () => {
1390 if (finished) return;
1391 finished = true;
1392 process.off("SIGINT", shutdown);
1393 process.off("SIGTERM", shutdown);
1394 process.stdin.off("end", shutdown);
1395 process.stdin.off("close", shutdown);
1396 resolveExit();
1397 };
1398
1399 const closeBoth = (): Promise<void> => {
1400 if (!closePromise) {
1401 closing = true;
1402 closePromise = Promise.allSettled([stdio.close(), http.close()]).then(() => undefined);
1403 }
1404 return closePromise;
1405 };
1406
1407 function shutdown() {
1408 finish();
1409 void closeBoth();
1410 }
1411
1412 const isAbortDuringClose = (error: Error): boolean =>
1413 error.name === "AbortError" || error.message.toLowerCase().includes("aborted");
1414
1415 const reportError = (context: string, cause: unknown) => {
1416 const error = toError(cause);
1417 if (closing && isAbortDuringClose(error)) return;
1418 console.error(`Executor MCP bridge ${context}: ${error.message}`);
1419 };
1420
1421 const forwardMessage =
1422 (send: (message: JSONRPCMessage) => Promise<void>, context: string) =>

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