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

Function runStdioMcpSession

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

Source from the content-addressed store, hash-verified

1450};
1451
1452const runStdioMcpSession = (input: {
1453 readonly elicitationMode: "browser" | "model";
1454 readonly artifacts: boolean;
1455}) =>
1456 Effect.gen(function* () {
1457 // `executor mcp` never owns the local database. If a local server is already
1458 // running, bridge this stdio client to it; otherwise ensure a durable
1459 // background daemon is up and bridge to that. ensureDaemon is the race-safe
1460 // election: concurrent cold starts elect one owner and the losers wait for
1461 // its manifest (waitForDaemonStartupTarget) rather than failing. Bridging
1462 // means many MCP clients, the web UI, and the desktop app share one owner,
1463 // and that owner's lifetime is never tied to a transient MCP client.
1464 const active = yield* readActiveLocalServerManifest();
1465 if (active) {
1466 yield* Effect.promise(() =>
1467 runMcpHttpBridge({
1468 manifest: active,
1469 elicitationMode: input.elicitationMode,
1470 artifacts: input.artifacts,
1471 }),
1472 );
1473 return;
1474 }
1475
1476 // No reachable owner yet: ensure one. If we lose the election (another
1477 // process became owner first), ensureDaemon may fail, but the winner's
1478 // manifest is then reachable, so re-read it and bridge to that instead.
1479 const elected = yield* ensureDaemon(DEFAULT_BASE_URL).pipe(
1480 Effect.flatMap(() => readActiveLocalServerManifest()),
1481 Effect.catch((error) =>
1482 readActiveLocalServerManifest().pipe(
1483 Effect.flatMap((manifest) => (manifest ? Effect.succeed(manifest) : Effect.fail(error))),
1484 ),
1485 ),
1486 );
1487 if (!elected) {
1488 return yield* Effect.fail(
1489 new Error("The local Executor daemon started but did not advertise a reachable manifest."),
1490 );
1491 }
1492 yield* Effect.promise(() =>
1493 runMcpHttpBridge({
1494 manifest: elected,
1495 elicitationMode: input.elicitationMode,
1496 artifacts: input.artifacts,
1497 }),
1498 );
1499 });
1500
1501const scope = Options.string("scope").pipe(
1502 Options.optional,

Callers 1

main.tsFile · 0.85

Calls 2

runMcpHttpBridgeFunction · 0.85
ensureDaemonFunction · 0.85

Tested by

no test coverage detected