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

Function runBackgroundDaemonStart

apps/cli/src/main.ts:1300–1334  ·  view source on GitHub ↗
(input: {
  port: number;
  hostname: string;
  allowedHosts: ReadonlyArray<string>;
})

Source from the content-addressed store, hash-verified

1298// command is idempotent: re-running while a daemon is already up should report success
1299// (matching the auto-start behaviour) rather than fail or spawn a duplicate.
1300const runBackgroundDaemonStart = (input: {
1301 port: number;
1302 hostname: string;
1303 allowedHosts: ReadonlyArray<string>;
1304}): Effect.Effect<void, Error, FileSystem.FileSystem | PlatformPath.Path> =>
1305 Effect.gen(function* () {
1306 const host = canonicalDaemonHost(input.hostname);
1307 const requestedUrl = daemonBaseUrl(host, input.port);
1308 const target = yield* resolveDaemonTarget(requestedUrl);
1309
1310 if (yield* isServerReachable(target.baseUrl)) {
1311 console.log(`Daemon already running at ${target.baseUrl}.`);
1312 return;
1313 }
1314
1315 if (!canAutoStartLocalDaemonForHost(host)) {
1316 return yield* Effect.fail(
1317 new Error(
1318 [
1319 `Cannot background a daemon for non-local host ${host}.`,
1320 `Use --foreground or bind to localhost / 127.0.0.1.`,
1321 ].join("\n"),
1322 ),
1323 );
1324 }
1325
1326 const startBaseUrl = yield* spawnAndWaitForDaemon({
1327 host,
1328 scopeId: target.scopeId,
1329 preferredPort: input.port,
1330 allowedHosts: input.allowedHosts,
1331 });
1332
1333 console.log(`Daemon ready on ${startBaseUrl}`);
1334 }).pipe(Effect.mapError(toError));
1335
1336// ---------------------------------------------------------------------------
1337// Stdio MCP session: a pure stdio <-> HTTP bridge to the owning local daemon.

Callers 1

main.tsFile · 0.85

Calls 7

canonicalDaemonHostFunction · 0.90
daemonBaseUrlFunction · 0.85
resolveDaemonTargetFunction · 0.85
isServerReachableFunction · 0.85
spawnAndWaitForDaemonFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected