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

Function runStdioMcpSession

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

Source from the content-addressed store, hash-verified

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

Callers 1

main.tsFile · 0.85

Calls 2

runMcpHttpBridgeFunction · 0.85
ensureDaemonFunction · 0.85

Tested by

no test coverage detected