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

Function runBackgroundDaemonStart

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

Source from the content-addressed store, hash-verified

1275// command is idempotent: re-running while a daemon is already up should report success
1276// (matching the auto-start behaviour) rather than fail or spawn a duplicate.
1277const runBackgroundDaemonStart = (input: {
1278 port: number;
1279 hostname: string;
1280 allowedHosts: ReadonlyArray<string>;
1281}): Effect.Effect<void, Error, FileSystem.FileSystem | PlatformPath.Path> =>
1282 Effect.gen(function* () {
1283 const host = canonicalDaemonHost(input.hostname);
1284 const requestedUrl = daemonBaseUrl(host, input.port);
1285 const target = yield* resolveDaemonTarget(requestedUrl);
1286
1287 if (yield* isServerReachable(target.baseUrl)) {
1288 console.log(`Daemon already running at ${target.baseUrl}.`);
1289 return;
1290 }
1291
1292 if (!canAutoStartLocalDaemonForHost(host)) {
1293 return yield* Effect.fail(
1294 new Error(
1295 [
1296 `Cannot background a daemon for non-local host ${host}.`,
1297 `Use --foreground or bind to localhost / 127.0.0.1.`,
1298 ].join("\n"),
1299 ),
1300 );
1301 }
1302
1303 const startBaseUrl = yield* spawnAndWaitForDaemon({
1304 host,
1305 scopeId: target.scopeId,
1306 preferredPort: input.port,
1307 allowedHosts: input.allowedHosts,
1308 });
1309
1310 console.log(`Daemon ready on ${startBaseUrl}`);
1311 }).pipe(Effect.mapError(toError));
1312
1313// ---------------------------------------------------------------------------
1314// 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