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

Function runMcpHttpBridge

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

Source from the content-addressed store, hash-verified

1334 * when stdin closes or the daemon connection drops; close is best-effort.
1335 */
1336const runMcpHttpBridge = async (input: {
1337 readonly manifest: ExecutorLocalServerManifest;
1338 readonly elicitationMode: "browser" | "model";
1339}): Promise<void> => {
1340 const stdio = new StdioServerTransport();
1341 const authorization = getExecutorServerAuthorizationHeader(input.manifest.connection);
1342 const http = new StreamableHTTPClientTransport(
1343 mcpUrlForActiveLocalServer(input.manifest.connection, input.elicitationMode),
1344 authorization ? { requestInit: { headers: { Authorization: authorization } } } : undefined,
1345 );
1346
1347 let finished = false;
1348 let closing = false;
1349 let closePromise: Promise<void> | null = null;
1350 let resolveExit: () => void = () => {};
1351 const waitForExit = new Promise<void>((resolve) => {
1352 resolveExit = resolve;
1353 });
1354
1355 const finish = () => {
1356 if (finished) return;
1357 finished = true;
1358 process.off("SIGINT", shutdown);
1359 process.off("SIGTERM", shutdown);
1360 process.stdin.off("end", shutdown);
1361 process.stdin.off("close", shutdown);
1362 resolveExit();
1363 };
1364
1365 const closeBoth = (): Promise<void> => {
1366 if (!closePromise) {
1367 closing = true;
1368 closePromise = Promise.allSettled([stdio.close(), http.close()]).then(() => undefined);
1369 }
1370 return closePromise;
1371 };
1372
1373 function shutdown() {
1374 finish();
1375 void closeBoth();
1376 }
1377
1378 const isAbortDuringClose = (error: Error): boolean =>
1379 error.name === "AbortError" || error.message.toLowerCase().includes("aborted");
1380
1381 const reportError = (context: string, cause: unknown) => {
1382 const error = toError(cause);
1383 if (closing && isAbortDuringClose(error)) return;
1384 console.error(`Executor MCP bridge ${context}: ${error.message}`);
1385 };
1386
1387 const forwardMessage =
1388 (send: (message: JSONRPCMessage) => Promise<void>, context: string) =>
1389 (message: JSONRPCMessage) => {
1390 void send(message).then(undefined, (cause: unknown) => {
1391 reportError(context, cause);
1392 shutdown();
1393 });

Callers 1

runStdioMcpSessionFunction · 0.85

Calls 8

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

Tested by

no test coverage detected