openpencil/tests/engine/mcp
Danila Poyarkov 3c016e9573
fix(mcp): close orphaned servers after app disconnects (#494)
* fix(mcp): close orphaned servers that no app ever claims

- Add ServerOptions.appAttachTimeoutMs: if no app registers within this
  window after startup, the server closes itself and removes its
  discovery file, instead of squatting the port indefinitely.
- Wire it through the openpencil-mcp-http CLI as
  OPENPENCIL_MCP_APP_TIMEOUT_MS (opt-in, unset/0 disables it — a bare
  CLI invocation for manual testing should not self-terminate).
- The desktop app opts in with a 30s timeout when it spawns the server.

Without this, a server that outlives its spawning app (renderer crash,
forced reload) keeps holding its port with a stale discovery file. The
app's liveness check only asks whether something answers /health, not
whether an app has ever registered (see /health's no_app status) — so
every later launch finds the orphan already listening and defers to
it, and MCP tool calls fail with "app is not connected" until someone
manually kills the orphaned process. Closing self-caused orphans at
the source means the next launch finds no discovery file and takes
the normal fresh-spawn path.

Fixes #488

* fix(mcp): clean up servers after app disconnects

- Re-arm the orphan watchdog when the registered app disconnects

- Cancel pending shutdown when the app reconnects within the grace period

- Reject timeout values that overflow the runtime timer range

* test(mcp): make watchdog reconnect coverage deterministic

- Wait for the disconnected health state before reconnecting

- Report distinct safe-integer and timer-range validation errors

---------

Co-authored-by: swe-sanad <sanad.arousi@export119.com>
2026-08-12 18:44:31 +03:00
..
server fix(mcp): close orphaned servers after app disconnects (#494) 2026-08-12 18:44:31 +03:00
stdio refactor: standardize acronym casing 2026-08-10 15:48:16 +03:00
test-support refactor(mcp): align transport domain structure 2026-07-25 22:59:59 +03:00
transport refactor(mcp): align transport domain structure 2026-07-25 22:59:59 +03:00
auth.test.ts fix(mcp): harden local file and token access 2026-07-25 21:03:29 +03:00
browser-rpc.test.ts refactor: standardize acronym casing 2026-08-10 15:48:16 +03:00
path-scoping.test.ts fix(mcp): harden local file and token access 2026-07-25 21:03:29 +03:00
result.test.ts fix(mcp): harden tool responses 2026-05-31 18:14:10 +03:00
tools.test.ts fix(mcp): harden tool responses 2026-05-31 18:14:10 +03:00