Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1mcp app Agent runServeBackground

From Leeroopedia
Knowledge Sources
Domains Process_Management, CLI
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete CLI command launcher that starts a detached background supervisor process owning a runtime scope, with PID file management, ownership claiming, and readiness probing.

Description

The runServeBackground function is the entry point for `serve --background`. It claims the runtime scope via ownership claiming, writes a background launch config, spawns a detached supervisor process that runs `runBackgroundRuntimeSupervisor`, and waits for the worker to become ready via a readiness probe. The supervisor owns the runtime scope and remains resident across worker crashes and retries. The launcher returns once the worker is ready, leaving the supervisor running in the background.

Usage

Import this function when you need to:

  • Start a 1MCP runtime as a detached background process
  • Claim runtime scope ownership before starting the supervisor
  • Probe worker readiness before returning from the launcher
  • Write background launch configuration for the supervisor

Code Reference

Source Location

  • Repository: 1MCP Agent
  • File: src/commands/serve/serveBackground.ts (L118-506), src/core/server/backgroundRuntimeSupervisor.ts (L134-220)

Signature

export async function runServeBackground(
  parsedArgv: ServeOptions,
  deps?: RunBackgroundDeps,
): Promise<void>;

export async function runBackgroundRuntimeSupervisor(
  options: BackgroundSupervisorOptions,
  dependencies: BackgroundSupervisorDependencies,
): Promise<void>;

export const BACKGROUND_RESTART_DELAYS_MS = [1_000, 2_000, 4_000, 8_000, 16_000] as const;
export const BACKGROUND_STABLE_RESET_MS = 5 * 60 * 1_000;

Import

import { runServeBackground } from '@src/commands/serve/serveBackground.js';
import { runBackgroundRuntimeSupervisor, BACKGROUND_RESTART_DELAYS_MS } from '@src/core/server/backgroundRuntimeSupervisor.js';

I/O Contract

Inputs

Name Type Required Description
parsedArgv ServeOptions Yes Full serve options
configDir string Yes Runtime scope config directory
workerCommand string Yes Worker executable command
workerArgs readonly string[] Yes Immutable worker arguments

Outputs

Name Type Description
supervisor process detached process Background supervisor owning the scope
PID file file Runtime scope ownership record
supervisor state file Background supervisor state with restart counter

Usage Examples

Start Background Runtime

1mcp serve --background --port 3000
1mcp serve --background --config /path/to/config.json

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment