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

Function runBackgroundDaemonStart

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

Source from the content-addressed store, hash-verified

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