mcp-pacemaker 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +452 -0
  2. package/CONTRIBUTING.md +222 -0
  3. package/LICENSE +21 -0
  4. package/README.md +621 -0
  5. package/SECURITY.md +120 -0
  6. package/THIRD_PARTY_NOTICES.txt +366 -0
  7. package/autostart/windows/launcher.vbs +11 -0
  8. package/autostart/windows/register-task.ps1 +63 -0
  9. package/bin/cli.mjs +880 -0
  10. package/bin/config-checks.mjs +62 -0
  11. package/bin/logs.mjs +465 -0
  12. package/bin/mcp-bridge.mjs +2162 -0
  13. package/bin/pooling-batch-scheduler.mjs +129 -0
  14. package/bin/pooling-batches.mjs +270 -0
  15. package/bin/pooling-config.mjs +577 -0
  16. package/bin/pooling-editor.mjs +128 -0
  17. package/bin/pooling-errors.mjs +23 -0
  18. package/bin/pooling-execution.mjs +104 -0
  19. package/bin/pooling-files.mjs +541 -0
  20. package/bin/pooling-trace.mjs +218 -0
  21. package/bin/pooling-writer.mjs +242 -0
  22. package/bin/prewarm.mjs +233 -0
  23. package/bin/server-metrics.mjs +69 -0
  24. package/bin/service-control.mjs +124 -0
  25. package/bin/shared-sessions.mjs +1083 -0
  26. package/bin/top.mjs +115 -0
  27. package/bin/update-check.mjs +153 -0
  28. package/bin/windows/PoolingSecurityHelper.build.json +42 -0
  29. package/bin/windows/PoolingSecurityHelper.exe +0 -0
  30. package/bin/windows/src/AssemblyInfo.cs +11 -0
  31. package/bin/windows/src/PoolingNativeFiles.cs +678 -0
  32. package/bin/windows/src/PoolingSecurityHelper.cs +178 -0
  33. package/bin/windows/src/PoolingSecurityReader.cs +50 -0
  34. package/docs/shared-sessions.md +181 -0
  35. package/examples/servers.example.json +31 -0
  36. package/package.json +77 -0
  37. package/supervisor/bridge-child.mjs +14 -0
  38. package/supervisor/supervise.mjs +172 -0
  39. package/supervisor/supervise.ps1 +23 -0
  40. package/supervisor/supervise.sh +11 -0
  41. package/tools/windows-security-helper/README.md +238 -0
  42. package/tools/windows-security-helper/build.ps1 +262 -0
  43. package/ui/dist/THIRD_PARTY_NOTICES.txt +366 -0
  44. package/ui/dist/assets/index-CaLPg0c-.css +1 -0
  45. package/ui/dist/assets/index-CgPruWYi.js +9 -0
  46. package/ui/dist/index.html +14 -0
  47. package/ui/dist/third-party-manifest.json +597 -0
package/README.md ADDED
@@ -0,0 +1,621 @@
1
+ # mcp-pacemaker
2
+
3
+ **Keep your MCP servers alive across editor restarts, reboots, and token expiry.** The long-running bridge is dependency-free; a small CLI (commander · clack · picocolors) handles setup.
4
+
5
+ MCP hosts — editors (VS Code, Cursor, Claude Desktop) **and** CLIs (Claude Code, Copilot CLI,
6
+ Codex, Gemini) — run stdio MCP servers as child processes. When the host restarts, crashes, or
7
+ exits (every one-shot CLI run), **those servers die**. `mcp-pacemaker` runs your servers as
8
+ children of a small, long-lived bridge and exposes each over the MCP HTTP+SSE / Streamable HTTP
9
+ transport. Multiple hosts use one bridge, with an isolated child per session by default.
10
+ Opt into pre-warming or reuse one initialized child for compatible stateless tools sessions
11
+ with [shared mode](#shared-mode). Wire hosts to one bridge, or give each its own.
12
+ A cross-platform supervisor + OS auto-start keep the bridge itself alive across reboots and
13
+ sleep/wake, and a pluggable auth layer injects a fresh token per request for HTTP servers.
14
+
15
+ After a restart, a returning client can reuse a recorded session ID to re-establish its handshake
16
+ against a fresh server. This does not restore arbitrary tool state or preserve TCP connections.
17
+ Clients that stop retrying after a dropped connection may still need a reload; socket handoff
18
+ is separate planned work.
19
+
20
+ ## Quick start
21
+
22
+ This README describes **2.0.x**. The current line is 2.x; the explicit maintenance line is
23
+ 1.3.x. See the [legacy documentation](https://github.com/girishkvs/mcp-pacemaker/blob/v1.3.1/README.md)
24
+ for its immediate-save behavior and [support policy](SECURITY.md#supported-versions).
25
+
26
+ Compatibility gates distinguish immutable **1.3.0 / 2.0.0** from the **1.3.1 / 2.0.1** candidates.
27
+ A 2.x client handles legacy immediate saves. A 1.x client cannot write pooling settings to a
28
+ 2.x bridge: update the CLI and refresh old dashboard tabs. Before downgrading, settle pending
29
+ or interrupted transactions with 2.x. See the [real-version gates](CONTRIBUTING.md#real-version-compatibility-gates)
30
+ for exact pairs; other minor versions are not covered.
31
+
32
+ ```bash
33
+ npm i -g github:girishkvs/mcp-pacemaker#v2.0.1
34
+ mcp-pacemaker init
35
+ ```
36
+
37
+ That one command does the whole setup:
38
+
39
+ 1. **detects** every MCP host you have installed — editors and CLIs,
40
+ 2. **imports** the servers already configured in them into `~/.mcp-pacemaker/servers.json`,
41
+ 3. **rewrites** each host's config to point at the bridge (backing every file up first),
42
+ 4. **registers** OS auto-start so the bridge returns after a reboot,
43
+ 5. **starts** the bridge and prints what it wired.
44
+
45
+ Nothing is written before you see it: `mcp-pacemaker plan --client <host>` shows the exact
46
+ changes, every config write leaves a `.bak`, and `mcp-pacemaker uninstall` restores them.
47
+
48
+ After setup, bare `mcp-pacemaker` reports status:
49
+
50
+ ```bash
51
+ mcp-pacemaker # status: bridges, wired hosts, servers
52
+ mcp-pacemaker top # live terminal dashboard
53
+ mcp-pacemaker doctor # diagnose config, reachability, wiring
54
+ ```
55
+
56
+ <details>
57
+ <summary>Prefer to drive it yourself? The same steps, one at a time</summary>
58
+
59
+ Every command takes any host id — `vscode`, `cursor`, `claude`, `claude-code`, `copilot-cli`,
60
+ `codex`, `gemini` (see [Supported hosts](#supported-hosts)). `--from` / `--client` below are
61
+ just examples; substitute whichever you use.
62
+
63
+ ```bash
64
+ mcp-pacemaker import --from <host> # build servers.json from an existing host
65
+ mcp-pacemaker plan --client <host> # dry run: show what install would change
66
+ mcp-pacemaker install --client <host> # wire one host (--port N gives it its own bridge)
67
+ mcp-pacemaker start # start the bridge
68
+ ```
69
+
70
+ ```bash
71
+ # e.g. import from Cursor, then wire three hosts to the same bridge
72
+ mcp-pacemaker import --from cursor
73
+ mcp-pacemaker install --client cursor
74
+ mcp-pacemaker install --client claude-code
75
+ mcp-pacemaker install --client gemini
76
+ ```
77
+
78
+ Run `install` once per host you want wired; repeat with `--port N` instead to give a host its
79
+ own bridge. `emit` prints the config entries without writing anything, if you'd rather paste
80
+ them in.
81
+
82
+ </details>
83
+
84
+ ## Why not just use supergateway / mcp-proxy?
85
+
86
+ Those are great, mature stdio↔SSE bridges. `mcp-pacemaker` targets a different problem —
87
+ *durable local hosting on a dev workstation* — and adds things they don't:
88
+
89
+ | | supergateway | mcp-proxy | **mcp-pacemaker** |
90
+ |---|---|---|---|
91
+ | stdio → SSE | ✅ | ✅ | ✅ |
92
+ | Streamable HTTP | ✅ | ✅ | ✅ |
93
+ | Dependencies | npm tree | PyPI tree | **bridge: zero** · tiny setup CLI |
94
+ | Process supervision | ❌ | ❌ | ✅ |
95
+ | OS auto-start (logon / unlock / boot) | ❌ | ❌ | ✅ (Windows / macOS / Linux) |
96
+ | Dynamic per-request token (from a CLI, auto-refresh) | ❌ (static) | ❌ (static/OAuth2) | ✅ |
97
+ | Sessions survive the bridge restarting | ❌ | ❌ | ✅ |
98
+ | Scheduled recycle for interactively-authenticated servers | ❌ | ❌ | ✅ |
99
+ | One-command import + client wiring | ❌ | ❌ | ✅ |
100
+ | Web + terminal dashboard, HTTP API | ❌ | ❌ | ✅ |
101
+
102
+ ## Supported hosts
103
+
104
+ Editors and CLIs are auto-detected and wired to the bridge. Most hosts get Streamable HTTP
105
+ (`/<name>/mcp`); Cursor and Claude Desktop are wired over SSE (`/<name>/sse`) until Streamable
106
+ HTTP is verified there. The bridge centralizes auth, so hosts talk to it unauthenticated over
107
+ loopback.
108
+
109
+ | Host | Type | Config | Wiring | Transport |
110
+ |---|---|---|---|---|
111
+ | VS Code | editor | `Code/User/mcp.json` | direct edit | Streamable HTTP |
112
+ | Cursor | editor | `~/.cursor/mcp.json` | direct edit | SSE |
113
+ | Claude Desktop | editor | `claude_desktop_config.json` | direct edit | SSE |
114
+ | Claude Code | CLI | `~/.claude.json` | native `claude mcp add` | Streamable HTTP |
115
+ | Copilot CLI | CLI | `~/.copilot/mcp-config.json` | direct edit | Streamable HTTP |
116
+ | Codex CLI | CLI | `~/.codex/config.toml` | TOML (comment-preserving) | Streamable HTTP |
117
+ | Gemini CLI | CLI | `~/.gemini/settings.json` | direct edit | Streamable HTTP |
118
+
119
+ **Topologies:** wire every host to one shared bridge (default), or give each host its own bridge
120
+ (`install --client X --port N`) — or any mix. `status`/`doctor` report all bridges + wired hosts.
121
+
122
+ ## Install
123
+
124
+ Use a maintained **Node.js 22 or 24** release. Node 20 remains a compatibility target but is
125
+ end-of-life, not a recommended secure runtime. The bridge has no npm runtime dependencies;
126
+ the setup CLI and dashboard have their own dependencies.
127
+
128
+ GitHub and npm publication are separate. Until the npm release is announced from
129
+ [this repository](https://github.com/girishkvs/mcp-pacemaker/releases), use the pinned GitHub
130
+ release. Do not assume that an npm package with a matching name is this project.
131
+
132
+ ```bash
133
+ npm i -g github:girishkvs/mcp-pacemaker#v2.0.1
134
+ # Deliberate legacy installation instead:
135
+ npm i -g github:girishkvs/mcp-pacemaker#v1.3.1
136
+ ```
137
+
138
+ After npm publication, `mcp-pacemaker@latest` selects the current 2.x line and
139
+ `mcp-pacemaker@legacy` selects maintained 1.3.x. Verify the official listing's repository and
140
+ maintainer before installing. For a repeatable installation, choose an exact released version:
141
+
142
+ ```bash
143
+ npm i -g mcp-pacemaker@2.0.1
144
+ # Or, deliberately:
145
+ npm i -g mcp-pacemaker@1.3.1
146
+ ```
147
+
148
+ `@1` and `@2` are version ranges, not the maintained channels. They can select a version
149
+ withdrawn from a channel. `upgrade --self` resolves the installed major's channel and prints
150
+ an exact-version command; it never installs or downgrades anything.
151
+
152
+ Use a durable installation directory for a long-running service. Do not register autostart
153
+ from an `npx` cache: that cache may be removed later. Bare CLI invocation can enter the setup
154
+ wizard; use `--version` for a read-only installation check.
155
+
156
+ Windows setup also needs PowerShell 7 (`pwsh`) and Windows Script Host for its launcher.
157
+ Automatic configuration edits need .NET Framework 4.6.2 or newer. The bundled helper is
158
+ unsigned; npm provenance is not Authenticode signing or an application-control allowlist.
159
+ Windows ARM64 is not validated.
160
+
161
+ ### Command reference
162
+
163
+ | Command | What it does |
164
+ |---|---|
165
+ | `init [--client a,b] [--yes]` | **The one you want.** Detect hosts, import, wire, auto-start, launch |
166
+ | `status` | Bridges, wired hosts, servers, and any server currently failing |
167
+ | `reload` | Re-read `servers.json` into the running bridge without restarting it |
168
+ | `doctor` | Diagnose config, bridge reachability, host wiring |
169
+ | `prewarm [--port N] [--json]` | One view of stdio candidates, pools, shared-child state and measured process starts |
170
+ | `prewarm --enable <server> [--count N]` | Explicitly enable warm slots; `--disable <server>` turns them off |
171
+ | `logs [--follow] [--since 2h] [--server name] [--grep text]` | Read and filter durable logs, including retained rotation |
172
+ | `top` / `dashboard` | Live terminal UI / web dashboard |
173
+ | `plan --client <host>` | Dry run — show exactly what `install` would change |
174
+ | `import --from <host>` | Build `~/.mcp-pacemaker/servers.json` from an existing host |
175
+ | `install --client <host> [--port N]` | Wire one host (its own `--port` gives it its own bridge) |
176
+ | `emit --client <host>` | Print the config entries without writing anything |
177
+ | `start` / `stop` | Start or stop bridges (`--port` for one, else all) |
178
+ | `upgrade [--self]` | Re-wire hosts; `--self` only prints same-major, exact-version installation guidance |
179
+ | `update-check [--json]` | Compare the installed version with its maintained npm channel |
180
+ | `uninstall` | Stop the bridge, remove auto-start, restore configs from `.bak` |
181
+
182
+ > Package installation does not upgrade a running backend. `upgrade` rewires host configuration;
183
+ > it does not replace package files, restart an adopted backend, or update its autostart path.
184
+
185
+ > On start, pacemaker **probes the port**: it *adopts* an existing pacemaker bridge and *refuses to collide* with a foreign service (the wizard offers another port).
186
+
187
+ For a supervisor created by these patch releases, `stop --port N` verifies the matching
188
+ installation/configuration identity, waits for shutdown, and holds managed autostart until an
189
+ explicit `start --port N`. Normal OS shutdown does not create that hold. Use the matching
190
+ installation's CLI. Older or directly launched bridges have no managed stop record and are
191
+ refused rather than reported as stopped; disable their OS autostart and verify shutdown first.
192
+
193
+ On Linux/macOS the control socket lives beside the configuration, independent of `TMPDIR`.
194
+ Its complete path must fit within 103 UTF-8 bytes. `install` and `init` check this before
195
+ changing configuration or autostart; use a shorter configuration location rather than
196
+ relying on an implicit socket-location fallback.
197
+
198
+ Isolated and pooled stdio servers support HTTP+SSE (`/<name>/sse`) and Streamable HTTP
199
+ (`/<name>/mcp`). Shared mode requires Streamable HTTP.
200
+
201
+ `install` writes a `.bak` of your client config before touching it, and `uninstall` restores it.
202
+
203
+ ### Replacing or rolling back a running installation
204
+
205
+ Do not overwrite a package directory while its supervisor or bridge is running. Workers and
206
+ native helpers can load later, and dashboard assets are read from disk: replacement can mix
207
+ old and new code even when the original process still reports its old version.
208
+
209
+ Identify the selected port, installation directory, configuration directory and OS autostart
210
+ entry first. Settle or cancel 2.x batches, recover interrupted transactions with 2.x, and keep
211
+ a protected configuration backup. Disable the selected autostart entry and stop its supervisor
212
+ and bridge before replacing files; prove they cannot restart during replacement. Keep the
213
+ known-good installation until the new backend's version and instance identity are confirmed.
214
+ Re-register the intended autostart path, refresh dashboard tabs, and confirm host wiring.
215
+
216
+ One global npm prefix holds one package version and its shared command names. Installing the
217
+ other major there replaces it. Separate ports do not isolate credentials, nonces, logs or
218
+ session files: manual side-by-side operation needs separate durable code roots and separate
219
+ configuration directories, plus separate host/HOME state for CLI-managed setup.
220
+ `init/import --config` selects a source host configuration, not an isolated runtime profile.
221
+ There is no package `--profile` or `MCP_HOME` switch. Do not use an unscoped stop/uninstall
222
+ operation when another instance must remain running.
223
+
224
+ ## Dashboards
225
+
226
+ Two views of the same live state. Neither is required — the bridge runs headless — but both are
227
+ useful for answering "is this server actually up, and who is using it?"
228
+
229
+ ### Web dashboard
230
+
231
+ `mcp-pacemaker dashboard`, or open `http://127.0.0.1:<port>/ui`. It streams over SSE, so it
232
+ updates on its own without polling or a refresh.
233
+
234
+ ![Web dashboard: one card per server, showing sessions, warm pool, pids and connected agents](docs/images/dashboard.png)
235
+
236
+ Per server it shows the transport (`stdio` / `http`), the sharing policy (`pool` when pre-warming),
237
+ live sessions against the cap, request count, the actual OS pids, the warm-pool count, how long
238
+ ago it was last used, and **which clients are connected** — above, one server is shared by
239
+ VS Code and Claude Code while others are held by Copilot, Cursor and Codex. `Recycle` restarts
240
+ that server's processes; it is disabled for servers with no session to restart. The live log at
241
+ the bottom is the bridge's own log, filterable.
242
+
243
+ ### Pre-warming controls
244
+
245
+ The **Pre-Warming** tab puts every stdio candidate, current pool and shared server in one table.
246
+ It shows cold-start p50/p95, observed peak sessions, process starts, warm/target counts,
247
+ shared-child state and pending work, and an action.
248
+ HTTP proxies are excluded because the bridge does not launch their processes.
249
+
250
+ Choose **Enable pre-warming (N)** on a slow-server card or in the table. The button shows
251
+ the exact warm count and the extra resident-process cost before you click. Nothing enables
252
+ it automatically. **Disable pre-warming** removes idle warm children without killing active
253
+ sessions after the change is applied.
254
+
255
+ Changes are batched in a **complete pending copy** of `servers.json`. Every accepted change
256
+ resets a five-second countdown. When editing stops, reload validates the pending copy, retains
257
+ the original as `servers.previous.json`, flips the pending file into place, and activates the
258
+ new settings. The dashboard shows **Pending** or **Applying** until that succeeds; active
259
+ mode and warm counts are not changed early. **Reload now** flushes the same batch immediately.
260
+
261
+ **Cancel batch** discards a pending batch without changing active settings. **Undo batch**
262
+ stages the full previous configuration for another five-second batch, only if no intervening
263
+ active-file edit has occurred. These actions affect the entire batch; the dashboard names all
264
+ affected servers. An unrelated pending batch must be cancelled or applied before Undo.
265
+
266
+ The same controls are available without a browser:
267
+
268
+ ```sh
269
+ mcp-pacemaker prewarm --port 8791
270
+ mcp-pacemaker prewarm --port 8791 --enable filesystem --count 2
271
+ mcp-pacemaker prewarm --port 8791 --disable filesystem
272
+ # Changes are queued; the printed command cancels a pending batch or undoes it after application.
273
+ ```
274
+
275
+ Use `--config <path>` when the bridge's config and admin nonce are outside the default
276
+ directory. `--json` returns the measured snapshot. The CLI and UI use the same server
277
+ eligibility and recommendation data; a missing latency sample is not reported as a zero-cost
278
+ startup. The CLI returns after staging, so consecutive commands can join the same batch.
279
+ `prewarm` shows pending settings separately from active values. Config remains strict JSON,
280
+ not JSONC; the pending copy preserves unrelated JSON and requires a matching active revision.
281
+ Conflicts are reported rather than overwriting someone else's edit.
282
+
283
+ On Windows, saves run with the normal bridge account and use **directory-inherited auditing**.
284
+ The dashboard gives a non-blocking notice: custom per-file audit rules may not carry forward
285
+ to the new active copy. The retained original keeps its original metadata. No audit-read
286
+ privilege, UAC prompt, or permanently elevated bridge is required.
287
+
288
+ This does not permit broader access to configuration data. Candidates must have appropriate
289
+ access restrictions before any configuration bytes are written, and supported integrity
290
+ protections must be retained. Actual source write denial or unsupported protection remains
291
+ an error. Configuration operations run in a serialized worker so file inspection does not
292
+ block MCP traffic.
293
+
294
+ Windows security inspection uses the bundled, own-source .NET Framework helper rather than
295
+ starting PowerShell or compiling code on each write. Automatic edits require .NET Framework
296
+ 4.6.2 or later; modern Windows includes it. The helper's source, build instructions and
297
+ integrity metadata are [included in the package](tools/windows-security-helper/README.md).
298
+ Windows ARM64 execution is not yet validated.
299
+
300
+ Staging requests and file commits each have a bounded execution budget; the acknowledged
301
+ five-second batching delay does not keep the original HTTP request open. A commit already in
302
+ progress can finish after its deadline. The result distinguishes a pre-commit failure from
303
+ a committed or unknown outcome; it never automatically retries or claims a timed-out write
304
+ was rolled back.
305
+
306
+ The two file moves are not an atomic exchange. Reload coordinates them with validated recovery
307
+ state and non-replacing destination placement. Existing MCP traffic continues using the
308
+ previous in-memory configuration during the flip; an external reader can briefly find the
309
+ active path absent. Recovery must not overwrite a file created by an external editor.
310
+ Reread the settings after an uncertain result.
311
+
312
+ ### Upgrading from 1.3.0
313
+
314
+ Version 2.0.0 changes the configuration-save protocol; it does not require a new `servers.json`
315
+ format. Update the bridge and CLI together, then reload any open dashboard pages. A 1.3.0
316
+ client with a current nonce gets HTTP 409 before staging, with an instruction to update the
317
+ client. An already-open tab retains the old nonce after a bridge restart and gets HTTP 401;
318
+ refresh it to load the new dashboard and admin session.
319
+
320
+ Custom API clients must send `x-mcp-pooling-batch: 1`. Treat HTTP 202 as acceptance, not
321
+ completion, and follow the returned batch ID in `prewarm.batches` until it is applied,
322
+ cancelled or failed. CLI scripts must likewise wait for application before relying on new
323
+ settings. Undo now restores the complete batch and may affect several servers.
324
+ Updated clients still understand the immediate HTTP 200 response from a 1.3.0 bridge.
325
+
326
+ Before downgrading, cancel or apply pending changes with 2.0 and resolve any interrupted
327
+ transaction using 2.0 recovery. Stop that bridge before starting 1.3.0 with the active config.
328
+ Do not use a 1.3.0 binary to recover 2.0 transaction files or delete those files to bypass a
329
+ recovery error. Keep a protected backup of the configuration before changing versions.
330
+ If the writer worker exits, further automatic edits are refused until the bridge restarts;
331
+ existing MCP sessions continue.
332
+
333
+ ### Health
334
+
335
+ The `Health` tab runs the same checks as `mcp-pacemaker doctor`, so you can see them without a
336
+ terminal.
337
+
338
+ ![Health tab: Node version, config validity, per-server status and the admin nonce path](docs/images/health.png)
339
+
340
+ It checks the Node version, that the config parses, every server definition (including a stdio
341
+ server whose relative path will not resolve from the directory it would run in — a failure that
342
+ is otherwise silent until a client first calls it, and a server named after one of the bridge's
343
+ own routes, which is unreachable), any server currently failing, and that the admin nonce file
344
+ exists.
345
+
346
+ ### Terminal dashboard
347
+
348
+ `mcp-pacemaker top` is the same data as an Ink TUI, for when a browser is inconvenient:
349
+
350
+ ```
351
+ 🫀 mcp-pacemaker top ● :8850 · up 176s · v1.1.0
352
+ SERVER TYPE HEALTH SESS WARM REQ PID TOKEN ERROR / CLIENTS
353
+ filesystem stdio ok 2 1/1 8 186276,12 - ⇄ Visual Studio Code,Claude Code
354
+ github stdio ok 1 - 2 146436 - ⇄ GitHub Copilot
355
+ sqlite stdio ok 1 - 2 102108 - ⇄ Cursor
356
+ slow-tool stdio ok 1 - 2 103776 - ⇄ Codex CLI
357
+ search-api http FAIL×3 0 - 4 - 42m upstream rejected the crede
358
+ docs-api http ? 0 - 0 - -
359
+ ↑↓ select · r recycle · q quit
360
+ ```
361
+
362
+ `HEALTH` is `ok` when the last request to that server succeeded, `FAIL×n` after n consecutive
363
+ failures, and `?` when nothing has called it yet — deliberately not `ok`, since no evidence is not
364
+ the same as working. `WARM` shows `warm/minWarm` for pooled servers and `-` for the rest, `TOKEN`
365
+ the time left on a cached credential, and the last column either the connected clients or the last
366
+ error. `↑↓` selects a row and `r` recycles it.
367
+
368
+ ## Reading durable logs
369
+
370
+ ```sh
371
+ mcp-pacemaker logs --since 2h --server filesystem
372
+ mcp-pacemaker logs --follow --grep timeout
373
+ mcp-pacemaker logs --config /path/to/servers.json --since 2026-09-07T12:00:00Z
374
+ ```
375
+
376
+ `logs` reads `bridge.log.1` then `bridge.log` beside the selected config, including when
377
+ the bridge is stopped. `--since` accepts durations in seconds/minutes/hours/days or an ISO
378
+ timestamp with timezone. `--server` matches the exact log-header server name; `--grep` is
379
+ a case-insensitive literal match, not a regular expression. Matching multiline records retain
380
+ their header and context.
381
+
382
+ `--follow` handles complete new lines, split UTF-8 writes, truncation and rollover until
383
+ interrupted. It warns if rotation has already discarded an unread generation. Only retained
384
+ history is available; it cannot recover logs the bridge has deleted. Individual lines over
385
+ 1 MiB fail explicitly rather than being silently truncated.
386
+
387
+ ## Editing servers.json while it runs
388
+
389
+ Save the file and the bridge picks it up. Servers whose definition did not change are left
390
+ completely alone — same processes, same live sessions — so adding one server does not cost you the
391
+ fourteen that were already working:
392
+
393
+ ```bash
394
+ $ mcp-pacemaker reload # or just save the file; the bridge watches it
395
+ ✓ reloaded /Users/you/.mcp-pacemaker/servers.json on :8850
396
+ · added: postgres
397
+ · changed: github
398
+ · 2 session(s) restarted; untouched servers kept theirs
399
+ ```
400
+
401
+ A file that does not parse, or a server with neither `command` nor `url`, is **rejected whole** —
402
+ the bridge logs why and keeps serving the last good config, so a half-written save cannot take your
403
+ servers down. Set `MCP_CONFIG_WATCH=0` to require an explicit `reload` instead of watching.
404
+
405
+ ## Server health
406
+
407
+ Every server carries a health verdict in `/api/status`, `doctor`, `top` and the dashboard:
408
+
409
+ | State | Meaning |
410
+ |---|---|
411
+ | `ok` | The last request to this server succeeded |
412
+ | `failing` | Recent requests are failing, with a count of how many in a row |
413
+ | `unknown` | Nothing has called it yet |
414
+
415
+ This is passive and free — it is derived from traffic the bridge is already proxying. A JSON-RPC
416
+ error *from* the server counts as healthy (it answered); a 401/403, a 5xx, a spawn failure or a
417
+ non-zero exit counts as failing, and the state clears the moment a request succeeds again.
418
+
419
+ A server nobody calls stays `unknown` forever, which is honest but not much help if its credential
420
+ quietly expires overnight. `MCP_HEALTH_INTERVAL_MS` adds a periodic probe for HTTP servers so they
421
+ get a verdict without waiting for a client:
422
+
423
+ ```bash
424
+ MCP_HEALTH_INTERVAL_MS=300000 mcp-pacemaker start # probe every 5 minutes
425
+ ```
426
+
427
+ It is off by default because a probe is a real request to somebody else's service. Set
428
+ `"healthIntervalMinutes": 0` on a server to exclude just that one, or a number to give it its own
429
+ interval. stdio servers are not probed: a probe would mean spawning a process, which costs more
430
+ than the request it is meant to pre-empt.
431
+
432
+ ## HTTP API
433
+
434
+ Everything the dashboards show is plain HTTP on the same loopback port, so you can script it.
435
+ Read endpoints need no auth; administrative writes require a nonce.
436
+
437
+ | Endpoint | Method | Returns |
438
+ |---|---|---|
439
+ | `/status` | GET | Tiny liveness probe: `ok`, `service`, `version`, `port` and the server names. Used to tell a pacemaker bridge apart from a foreign service on the same port |
440
+ | `/api/status` | GET | Full snapshot — every server with sessions, pids, warm count, request count, `health`, `lastError`, connected clients |
441
+ | `/api/doctor` | GET | The health checks, as JSON |
442
+ | `/api/events` | GET (SSE) | The same snapshot pushed every 2s — what the dashboard consumes |
443
+ | `/api/logs` | GET (SSE) | Bridge log: replays the last 100 lines, then streams. For anything older, read `bridge.log` next to your config |
444
+ | `/admin/recycle/<name>` | POST | Restart a server's processes. Omit `<name>` to recycle everything |
445
+ | `/admin/reload` | POST | Flush a pending configuration batch, or re-read an externally edited `servers.json`. Only changed definitions are reconfigured |
446
+ | `/admin/servers/<name>/pooling` | POST | Stage enable/disable or batch cancel/undo with admin nonce, bounded input and a matching config revision |
447
+ | `/<name>/mcp` | POST/GET/DELETE | Streamable HTTP transport for that server |
448
+ | `/<name>/sse` | GET | HTTP+SSE transport for that server |
449
+ | `/.well-known/oauth-protected-resource/<name>` | GET | OAuth discovery relayed from the upstream, for HTTP servers where the client authenticates |
450
+
451
+ Pooling mutations require `x-mcp-pooling-batch: 1`. A staged change returns **HTTP 202** with
452
+ `pending: true`, a batch ID, a private cancel/undo receipt, and the public snapshot. Acceptance
453
+ is not activation. `prewarm.batches` in the snapshot reports bounded pending, applying and
454
+ completed outcomes; it does not expose receipt tokens or full configurations.
455
+ Clients without the batch header are rejected before a change is queued, rather than letting
456
+ an older client report a queued save as already enabled.
457
+ Rich snapshots carry an instance-scoped `snapshotVersion` so a delayed HTTP response or older
458
+ SSE frame cannot replace newer active settings or prematurely expire a batch receipt.
459
+
460
+ ```bash
461
+ # is a server actually running, and who is using it?
462
+ curl -s http://127.0.0.1:8850/api/status | jq '.servers[] | {name, sessions, pids, clients}'
463
+
464
+ # watch the bridge log
465
+ curl -N http://127.0.0.1:8850/api/logs
466
+
467
+ # force a restart of one server (nonce is written next to servers.json)
468
+ curl -X POST http://127.0.0.1:8850/admin/recycle/filesystem \
469
+ -H "x-mcp-nonce: $(cat ~/.mcp-pacemaker/admin.nonce)"
470
+ ```
471
+
472
+ `/admin/*` is guarded twice: the request must arrive on loopback, **and** carry the nonce that the
473
+ bridge writes to `admin.nonce` next to your config at startup. The nonce is new on every start, so
474
+ only same-box tooling that can read that file — the CLI, and the dashboard the bridge itself
475
+ served — can change anything.
476
+
477
+ ## servers.json
478
+
479
+ Config lives at `~/.mcp-pacemaker/servers.json`. `import` fills it from your existing client
480
+ config and **carries over `audience`/`auth`/`headers`**, so HTTP servers usually need no hand-editing.
481
+ See [`examples/servers.example.json`](examples/servers.example.json).
482
+
483
+ ```jsonc
484
+ {
485
+ "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "."] },
486
+
487
+ "my-api": {
488
+ "type": "http",
489
+ "url": "https://my-service.example.com/mcp",
490
+ "auth": { "type": "command", "command": "my-cli print-token", "refreshMinutes": 50 }
491
+ }
492
+ }
493
+ ```
494
+
495
+ **Auth options** (per HTTP server):
496
+
497
+ | `auth.type` | Behavior |
498
+ |---|---|
499
+ | `command` | Runs any command that prints a token on stdout; the result is cached and auto-refreshed (`refreshMinutes`). Provider-agnostic — see below. |
500
+ | `env` | Uses `process.env[var]`. |
501
+ | `static` | Fixed `header` + `value`. |
502
+ | `none` | No header is added — the **client** authenticates, and the bridge relays OAuth discovery and challenges for it. |
503
+
504
+ `auth.type: "command"` is deliberately just "run this and use what it prints", so it works with
505
+ whatever issues tokens in your environment. Some examples — none of these are special-cased:
506
+
507
+ ```jsonc
508
+ // Azure
509
+ { "type": "command", "command": "az account get-access-token --resource api://<id> --query accessToken -o tsv" }
510
+ // Google Cloud
511
+ { "type": "command", "command": "gcloud auth print-access-token" }
512
+ // AWS (e.g. a signed token from your own helper)
513
+ { "type": "command", "command": "aws-token-helper --profile prod" }
514
+ // HashiCorp Vault
515
+ { "type": "command", "command": "vault read -field=token secret/my-api" }
516
+ // 1Password / any secret manager
517
+ { "type": "command", "command": "op read op://vault/my-api/token" }
518
+ // A plain script
519
+ { "type": "command", "command": "./scripts/get-token.sh" }
520
+ ```
521
+
522
+ By default the token is sent as `Authorization: Bearer <token>`; set `header` to send it
523
+ somewhere else (for example `{ "header": "X-Api-Key" }`).
524
+
525
+ **How long a credential is cached.** If the command returns a JWT, its `exp` claim decides —
526
+ `refreshMinutes` is only an upper bound and a fallback for opaque credentials. This matters
527
+ because token CLIs serve from their own cache: `az account get-access-token` will hand back a
528
+ token it minted earlier that may be nearly spent, and trusting a flat window would keep a dead
529
+ token in play. If the upstream rejects a credential the bridge supplied, that 401 is reported on
530
+ the server (`doctor`, `/api/status` → `lastError`) and the credential is discarded rather than
531
+ reused — the client is never asked to log in for a server the bridge authenticates.
532
+
533
+ > **Azure shorthand.** A bare `"audience": "<res>"` expands to
534
+ > `az account get-access-token --resource <res> …`. That is a convenience for Azure users only —
535
+ > every other provider uses `auth.command` above.
536
+
537
+ ## Security
538
+
539
+ - The bridge binds **`127.0.0.1` only** (local loopback) — not reachable off-box.
540
+ - Tokens are **minted from your own already-authenticated CLI** and cached in memory; **never written to disk**.
541
+ - The **bridge** (the process that runs 24/7) has **zero third-party dependencies**; the setup CLI uses `commander` / `@clack/prompts` / `picocolors` / `smol-toml`, and the TUI adds `ink` / `react`.
542
+
543
+ ## Multi-agent & resource controls
544
+
545
+ Multiple hosts/agents can share one bridge — each gets its own isolated session by default,
546
+ and HTTP servers share the cached token across all of them. The dashboard, `top`, and
547
+ `mcp-pacemaker status` show **which agents are connected** to each server.
548
+
549
+ | Control | Env / config | Default | Effect |
550
+ |---|---|---|---|
551
+ | Idle reaper | `MCP_IDLE_TIMEOUT_MS` | `1800000` (30 min) | free Streamable HTTP children idle past the timeout. Safe by default because a returning client's session is transparently re-established. `0` disables |
552
+ | Concurrency cap | `MCP_MAX_SESSIONS_PER_SERVER`, or per-server `maxSessions` | `0` (unlimited) | reject new sessions past the cap (HTTP 503) |
553
+ | Queue at the cap | `MCP_QUEUE_TIMEOUT_MS` | `10000` (10s) | at the cap, wait this long for a slot before returning 503, so a burst is absorbed rather than failed. `0` rejects immediately |
554
+ | Sharing policy | per-server `sharing` (+ `minWarm`) | `isolated` | `isolated` = one child per session; `pool` pre-starts exclusive children; `shared` reuses one initialized child for compatible stateless tools sessions. Both alternatives require explicit activation |
555
+ | Cold-start gate | `MCP_MAX_CONCURRENT_SPAWNS`, `MCP_SPAWN_GATE_WAIT_MS` | `2`, `15000` | how many package-manager-backed servers may cold-start at once. `npx`, `uvx`, `dnx` and friends share one cache, and starting several together can corrupt it — this queues them. Detected from the command, or forced either way with per-server `sharedPackageCache`. Servers that use no package manager are never gated. If no slot frees within the wait, the spawn proceeds ungated rather than hold a client request. `0` disables |
556
+ | Pooling advice | `MCP_POOL_ADVICE_MS`, `MCP_WARM_MAX` | 2s, 8 | recommend pooling once a server's measured cold start passes this, and cap the suggested (and auto-sized) pool here. Advice only — the bridge never enables pooling on its own |
557
+ | Session resume | `MCP_RESUME`, `MCP_RESUME_TTL_MS` | on, 24h | re-establish a session id the bridge has not seen — after a restart, recycle or idle reap. `MCP_RESUME=0` disables |
558
+ | Scheduled recycle | per-server `recycleMinutes`, or `MCP_RECYCLE_MINUTES` | off | restart a server periodically, for servers holding a credential they can only refresh interactively |
559
+ | Request timeouts | `MCP_REQUEST_TIMEOUT_MS` / `MCP_INIT_TIMEOUT_MS` | 30s / 180s | `initialize` also pays for spawning the server, so it gets a longer budget than ordinary calls |
560
+ | Credential refresh | `MCP_TOKEN_REFRESH_LEAD_MS` | `300000` (5 min) | renew a cached token before it expires instead of discovering the expiry on a request. A JWT's own `exp` still caps how long it is cached |
561
+ | Durable log | `MCP_LOG_MAX_BYTES` | `5242880` (5 MB) | `bridge.log` next to your config, rolled to `bridge.log.1` at this size. `0` disables. The dashboard only keeps the last few hundred lines in memory, which a chatty client fills in minutes |
562
+ | Config watching | `MCP_CONFIG_WATCH` | on | reload `servers.json` when it is saved. `0` requires an explicit `mcp-pacemaker reload`. Either way, only servers whose definition changed are restarted, and an unparseable file is rejected without disturbing anything |
563
+ | Health probing | `MCP_HEALTH_INTERVAL_MS`, or per-server `healthIntervalMinutes` | off | periodically call an HTTP server so it has a health verdict before a client needs it. Passive health from real traffic is always on and costs nothing |
564
+
565
+ ### Measuring process churn
566
+
567
+ For stdio servers, `/api/status` reports `spawn.total` (successful process launches),
568
+ `spawn.attempts`, `spawn.failures`, `spawn.warmAdoptions`, `spawn.sessionStarts`, and
569
+ `spawn.sessionResumes`. Launches include classic SSE, Streamable HTTP, warm-pool refill,
570
+ and replacements after recycle or resume. Adopting an existing warm child does not count
571
+ as another launch. The unit is one bridge-launched process, not all of its descendants.
572
+
573
+ These cumulative counters do not share the 50-sample latency limit. They reset when the
574
+ bridge process restarts; compare snapshots only within the same `instanceId`. `startedAt`
575
+ identifies that interval. Save the final snapshot before a planned restart for a before/after
576
+ comparison. HTTP-proxied servers have no local process counters (`spawn: null`).
577
+
578
+ `spawn.samples` and p50/p95/max still describe the latest 50 directly observed, successful
579
+ cold initializations, not all launches. Latencies are `null` until observed; a warm child's
580
+ idle lifetime is not a cold-start sample. The existing `requests` count covers routed HTTP
581
+ requests, not just `tools/call`; do not label it as a tool-call count.
582
+
583
+ ### Shared mode
584
+
585
+ Set `"sharing": "shared"` on a stdio server only when its tools are stateless, operate on
586
+ explicit inputs and use one common credential context. This is an operator assertion, not
587
+ something latency or matching capabilities can prove. Leave workspace-, conversation- or
588
+ client-account-dependent servers isolated.
589
+
590
+ Compatible sessions have identical full initialization parameters, including `clientInfo`,
591
+ and empty client capabilities. One child receives one real initialization; each virtual session
592
+ gets its own IDs, progress, cancellation and tools-list cursors. Only the upstream's actual
593
+ tools capability is exposed. Roots, sampling, elicitation, tasks, resource subscriptions and
594
+ other stateful methods are not supported. Incompatible clients fail explicitly, without
595
+ silently falling back to a different mode.
596
+
597
+ Deleting one session leaves the others running. The initialized child is retained between
598
+ compatible reconnects for up to `sharedLingerMs` (30 minutes by default). Recycle drains work,
599
+ then replaces the generation on later use. A timeout or child exit never triggers automatic
600
+ replay of a potentially executed tool call.
601
+
602
+ The server keeps its existing credential provider and configured `recycleMinutes`. Shared
603
+ mode does not promise silent credential renewal. The dashboard and `prewarm` CLI show the
604
+ actual shared-child state, members, queued work and cumulative process launches.
605
+ See [the shared-session contract](docs/shared-sessions.md) for limits and failure semantics.
606
+
607
+ ## Uninstall
608
+
609
+ ```bash
610
+ npx mcp-pacemaker uninstall # stop bridge, remove auto-start, restore client config from .bak
611
+ ```
612
+
613
+ ## Project
614
+
615
+ - [CHANGELOG.md](CHANGELOG.md) — release notes
616
+ - [CONTRIBUTING.md](CONTRIBUTING.md) — development setup and how regression tests are expected to be proven
617
+ - [SECURITY.md](SECURITY.md) — threat model and how to report a vulnerability
618
+
619
+ ## License
620
+
621
+ MIT © Girish Konda