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

Function runBackgroundDaemonStart

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

Source from the content-addressed store, hash-verified

1319// command is idempotent: re-running while a daemon is already up should report success
1320// (matching the auto-start behaviour) rather than fail or spawn a duplicate.
1321const runBackgroundDaemonStart = (input: {
1322 port: number;
1323 hostname: string;
1324 allowedHosts: ReadonlyArray<string>;
1325}): Effect.Effect<void, Error, FileSystem.FileSystem | PlatformPath.Path> =>
1326 Effect.gen(function* () {
1327 const host = canonicalDaemonHost(input.hostname);
1328 const requestedUrl = daemonBaseUrl(host, input.port);
1329 const target = yield* resolveDaemonTarget(requestedUrl);
1330
1331 if (yield* isServerReachable(target.baseUrl)) {
1332 console.log(`Daemon already running at ${target.baseUrl}.`);
1333 return;
1334 }
1335
1336 if (!canAutoStartLocalDaemonForHost(host)) {
1337 return yield* Effect.fail(
1338 new Error(
1339 [
1340 `Cannot background a daemon for non-local host ${host}.`,
1341 `Use --foreground or bind to localhost / 127.0.0.1.`,
1342 ].join("\n"),
1343 ),
1344 );
1345 }
1346
1347 const startBaseUrl = yield* spawnAndWaitForDaemon({
1348 host,
1349 scopeId: target.scopeId,
1350 preferredPort: input.port,
1351 allowedHosts: input.allowedHosts,
1352 });
1353
1354 console.log(`Daemon ready on ${startBaseUrl}`);
1355 }).pipe(Effect.mapError(toError));
1356
1357// ---------------------------------------------------------------------------
1358// 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