Skip to content

Resilient MCP Broker

magalz edited this page Nov 26, 2026 · 1 revision

Resilient MCP Broker (ignis-swarm_broker)

The bundled ignis-broker (scripts/ignis-broker.mjs) is a zero-dependency Node.js ESM MCP broker daemon that keeps context overhead minimal and prevents mid-session MCP server crashes or disconnects from breaking long /swarm workflows.


1. Architecture

flowchart LR
    AGY["Antigravity Agent\n(4 Compact Meta-Tools)"] -->|"stdio JSON-RPC"| BR["mcp-bridge\n(scripts/ignis-broker.mjs mcp-bridge)"]
    CLI["Shell / Subagent CLI\n(scripts/ignis-broker.mjs)"] -->|"HTTP + Bearer Token"| DM
    BR -->|"127.0.0.1 ephemeral port\nBearer Token (timingSafeEqual)"| DM["Detached ignis-broker Daemon\n(Lazy Auto-Start · Version-Safe)"]
    DM -->|"Pooled stdio\n(per-workspace or shared)"| S1["Local stdio MCPs\n(e.g., memtrace, firecrawl)"]
    DM -->|"Streamable HTTP / SSE"| S2["Remote HTTP MCPs\n(e.g., Linear, ItsAPlan)"]
Loading

Key design properties (see ADR-001, ADR-002, ADR-003):

  • Zero external dependencies: Pure Node.js >= 20 ESM.
  • Lazy auto-start & version-safe reuse: Any MCP bridge or CLI call auto-starts the detached daemon on 127.0.0.1 (ephemeral port, random Bearer token checked with crypto.timingSafeEqual). Older in-memory bridges reuse newer same-major daemons (isDaemonVersionAcceptable) instead of killing them on plugin upgrades.
  • Concurrent cold-start deduplication: Parallel calls to an idle backend share a single in-flight connection promise (pendingConnects), and live config edits invalidate pools automatically via configDigest.
  • Cross-platform Windows .cmd/.bat support: Unwraps npm/Node .cmd shims directly to process.execPath with shell: false, and hardens non-Node .cmd/.bat quoting against command injection.
  • Cross-platform process-tree cleanup: Reaps orphaned backend trees cleanly on eviction or daemon shutdown.

2. Dual Interface: 4 MCP Meta-Tools + CLI Fallback

Path A — MCP Gateway (ignis-swarm_broker)

Instead of injecting dozens of external MCP tool schemas into every turn, ignis-swarm_broker exposes 4 compact meta-tools:

Meta-Tool Parameters Purpose
broker_list { server?, filter?, cwd? } Omit server to list managed servers; pass server to list compact tool summaries (optional substring filter).
broker_describe { server, tool, cwd? } Fetch the full JSON input schema for one tool on demand.
broker_call { server, tool, arguments?, cwd?, full? } Execute a tool through the resilient supervisor (auto-reconnect + local→global failover + spill-to-file truncation).
broker_status { cwd? } Inspect daemon version, PID, port, uptime, active workspace pools, local config errors, and recent fallbacks.

Always pass cwd when calling workspace-scoped (perWorkspace: true) servers via MCP so the broker resolves <repo>/.agents/ignis-broker.json and anchors the right git repository root.

Path B — Cross-Platform CLI (scripts/ignis-broker.mjs)

Useful for shell-only subagents, troubleshooting, or administration. All 14 subcommands:

# Runtime operations
node <plugin-root>/scripts/ignis-broker.mjs status [--cwd <dir>] [--json]
node <plugin-root>/scripts/ignis-broker.mjs list [<server>] [--filter <text>] [--cwd <dir>] [--json]
node <plugin-root>/scripts/ignis-broker.mjs describe <server> <tool> [--cwd <dir>] [--json]
node <plugin-root>/scripts/ignis-broker.mjs call <server> <tool> [--args '<json>' | --args-file <file> | --stdin] [--max-bytes <n>] [--full] [--cwd <dir>] [--json]
node <plugin-root>/scripts/ignis-broker.mjs restart [<server>] [--cwd <dir>] [--json]
node <plugin-root>/scripts/ignis-broker.mjs stop

# Server discovery & registration (never modifies ~/.gemini/config/mcp_config.json)
node <plugin-root>/scripts/ignis-broker.mjs discover-mcp [--from <path>] [--json]
node <plugin-root>/scripts/ignis-broker.mjs register-mcp (--all | --servers a,b) [--from <path>] [--per-workspace a] [--cli-fallback a=cmd] [--json]
node <plugin-root>/scripts/ignis-broker.mjs add-http-mcp <name> <url> [--auth-env VAR] [--header-name Authorization] [--json]
node <plugin-root>/scripts/ignis-broker.mjs unregister-mcp <name> [--json]
node <plugin-root>/scripts/ignis-broker.mjs import-mcp [--from <path>] [--servers a,b] [--dry-run]

# Onboarding state
node <plugin-root>/scripts/ignis-broker.mjs onboarding (--get | --probe | --save '<json>' | --skip | --reset)

# Internal daemon & MCP stdio bridge entrypoints
node <plugin-root>/scripts/ignis-broker.mjs daemon [--port <n>]
node <plugin-root>/scripts/ignis-broker.mjs mcp-bridge

3. Configuration Precedence & Automatic Global Fallback

  1. Local override (checked first): <repo-root>/.agents/ignis-broker.json (discovered walking up from cwd to .git, stopping before your home directory).
  2. Global defaults (fallback): ~/.ignis-broker/servers.json (permissions 0o700 dir / 0o600 file).
  3. Failover: If a local override has invalid JSON or a local backend fails to connect/execute, the broker automatically falls back to the global server definition and surfaces _meta.fallbackFrom = "local" and _meta.localError (and reports it in status and SessionStart). Setting "enabled": false locally disables that server for the repo without falling back.

Example ~/.ignis-broker/servers.json

{
  "version": 1,
  "defaults": {
    "requestTimeoutMs": 120000,
    "startupTimeoutMs": 30000,
    "idleTimeoutSecs": 900,
    "maxWorkspaceInstances": 4,
    "maxOutputBytes": 16384,
    "maxOutputLines": 200,
    "spillTtlHours": 24,
    "retryOnTransportError": true
  },
  "servers": {
    "itsaplan": {
      "transport": "http",
      "url": "https://api.example.com/mcp",
      "headers": {
        "Authorization": "Bearer ${ITSAPLAN_TOKEN}"
      },
      "perWorkspace": false,
      "enabled": true
    },
    "memtrace": {
      "transport": "stdio",
      "command": "memtrace",
      "args": ["mcp"],
      "perWorkspace": true,
      "enabled": true
    }
  }
}

Default Tuning Keys

Key Default Description
requestTimeoutMs 120000 (2m) Per-tool-call timeout in milliseconds
startupTimeoutMs 30000 (30s) Backend handshake startup timeout
idleTimeoutSecs 900 (15m) Idle backend eviction timeout
maxWorkspaceInstances 4 Max pooled instances per perWorkspace: true server (LRU evicted)
maxOutputBytes 16384 (16 KB) Threshold before spilling large tool output to a file
maxOutputLines 200 Line threshold before spilling large tool output to a file
spillTtlHours 24 Retention window for spill files under ~/.ignis-broker/spill/
retryOnTransportError true Automatically reconnect and retry once on transport crash/EOF

4. Secrets (~/.ignis-broker/.env) & Spill-to-File Truncation

  • Secrets: Reference ${VAR_NAME} inside env, headers, or url in servers.json or .agents/ignis-broker.json. The broker expands values from ~/.ignis-broker/.env first, then process environment variables, and redacts all env/headers values in diagnostics.
  • Spill-to-file truncation: When a tool output exceeds maxOutputBytes or maxOutputLines (unless full: true is passed), the broker writes the full response to ~/.ignis-broker/spill/ and returns a compact preview plus _meta: { truncated: true, spillPath: "..." }. Agents can inspect targeted line ranges with read_file without flooding their context window.

Clone this wiki locally