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

Function runStdioMcpSession

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

Source from the content-addressed store, hash-verified

1479};
1480
1481const runStdioMcpSession = (input: {
1482 readonly elicitationMode: "browser" | "model";
1483 readonly artifacts: boolean;
1484 readonly searchTools: boolean;
1485}) =>
1486 Effect.gen(function* () {
1487 // `executor mcp` never owns the local database. If a local server is already
1488 // running, bridge this stdio client to it; otherwise ensure a durable
1489 // background daemon is up and bridge to that. ensureDaemon is the race-safe
1490 // election: concurrent cold starts elect one owner and the losers wait for
1491 // its manifest (waitForDaemonStartupTarget) rather than failing. Bridging
1492 // means many MCP clients, the web UI, and the desktop app share one owner,
1493 // and that owner's lifetime is never tied to a transient MCP client.
1494 const active = yield* readActiveLocalServerManifest();
1495 if (active) {
1496 yield* Effect.promise(() =>
1497 runMcpHttpBridge({
1498 manifest: active,
1499 elicitationMode: input.elicitationMode,
1500 artifacts: input.artifacts,
1501 searchTools: input.searchTools,
1502 }),
1503 );
1504 return;
1505 }
1506
1507 // No reachable owner yet: ensure one. If we lose the election (another
1508 // process became owner first), ensureDaemon may fail, but the winner's
1509 // manifest is then reachable, so re-read it and bridge to that instead.
1510 const elected = yield* ensureDaemon(DEFAULT_BASE_URL).pipe(
1511 Effect.flatMap(() => readActiveLocalServerManifest()),
1512 Effect.catch((error) =>
1513 readActiveLocalServerManifest().pipe(
1514 Effect.flatMap((manifest) => (manifest ? Effect.succeed(manifest) : Effect.fail(error))),
1515 ),
1516 ),
1517 );
1518 if (!elected) {
1519 return yield* Effect.fail(
1520 new Error("The local Executor daemon started but did not advertise a reachable manifest."),
1521 );
1522 }
1523 yield* Effect.promise(() =>
1524 runMcpHttpBridge({
1525 manifest: elected,
1526 elicitationMode: input.elicitationMode,
1527 artifacts: input.artifacts,
1528 searchTools: input.searchTools,
1529 }),
1530 );
1531 });
1532
1533const scope = Options.string("scope").pipe(
1534 Options.optional,

Callers 1

main.tsFile · 0.85

Calls 2

runMcpHttpBridgeFunction · 0.85
ensureDaemonFunction · 0.85

Tested by

no test coverage detected