diff --git a/robot-docs/mcp.md b/robot-docs/mcp.md index aa8591e50..322ad97a9 100644 --- a/robot-docs/mcp.md +++ b/robot-docs/mcp.md @@ -58,6 +58,9 @@ closes. Cold clients monitor both the preparer and runtime before opening their transport, through discovery and catalogue saving. Ownership transfers to a connector before preparation returns. See `prepare` and `initialise_catalogues` in [extension.gleam](../src/albedo/harness/extensions/mcp/extension.gleam). +[`bundle.gleam`](../src/albedo/harness/extensions/mcp/bundle.gleam) owns the +prepared bundle: preparation entrypoints, calls, adoption, close, and the +settings and editor probes. Server names, descriptions, and results are untrusted data. A failed or interrupted call may have had effects, so inspect those effects before retrying. @@ -65,8 +68,10 @@ A server-reported error appears in `isError`. A host failure raises `McpError`. See [extension.gleam](../src/albedo/harness/extensions/mcp/extension.gleam) and [mcp.py](../priv/python/albedo_plugins/mcp.py). [`dispatch.gleam`](../src/albedo/harness/extensions/mcp/dispatch.gleam) builds -each call's request and refuses a result larger than 4 MiB. The native call -worker in `albedo_mcp.erl` owns its deadline. +each call's request and refuses a result larger than 4 MiB. `bundle.call` runs +it in a worker that it kills 250 milliseconds after the operation's timeout. It +then closes that server's client, because a request the server never answered +leaves the connection in an unknown state. ## Catalogue policy and cache @@ -94,12 +99,12 @@ external-term cache through atom-keyed maps, not Gleam records. Keep that saved shape compatible with existing catalogues. `saved` decodes safely, so it creates the cache's atoms first; add any new key to `cache_atoms`. `servers.fingerprint` keys each saved -catalogue, so keep its term encoding stable as well. Native monitor, adoption, -and cleanup mechanisms remain in -[`albedo_mcp.erl`](../src/albedo/harness/extensions/mcp/albedo_mcp.erl) and -[`client.gleam`](../src/albedo/harness/extensions/mcp/client.gleam). +catalogue, so keep its term encoding stable as well. +[`client.gleam`](../src/albedo/harness/extensions/mcp/client.gleam) owns each +connection's process. [`albedo_mcp_stdio.erl`](../src/albedo/harness/extensions/mcp/albedo_mcp_stdio.erl) -owns the stdio port. +owns the stdio port, the only Erlang the extension keeps, because gleam_erlang +has no port binding. [`servers.gleam`](../src/albedo/harness/extensions/mcp/servers.gleam) resolves daemon variables, executables, and the launcher path. A stdio server's port unsets every daemon variable except a short safe list, then sets the server's @@ -115,24 +120,42 @@ validation precedes watcher and connector allocation. A failed connector handoff closes completed connectors and clients still awaiting transfer. [`connector.gleam`](../src/albedo/harness/extensions/mcp/connector.gleam) owns -connection, dial, refresh, waiter, and lifetime decisions. The native connector -owns monitors and attempts. Each dial attempt retains its client until client -ownership transfer is acknowledged. The connector then acknowledges the attempt -before answering waiters. Obsolete dial results close their own clients. A live -connection remains usable during catalogue refresh. +connection, dial, refresh, waiter, and lifetime decisions. The connector process +in [`connection.gleam`](../src/albedo/harness/extensions/mcp/connection.gleam) +owns monitors and attempts, with typed messages. Each dial attempt retains its +client until client ownership transfer is acknowledged. The connector then +acknowledges the attempt before answering waiters. Obsolete dial results close +their own clients. A live connection remains usable during catalogue refresh. [`watcher.gleam`](../src/albedo/harness/extensions/mcp/watcher.gleam) owns reason accumulation, activity coalescing, and completion-relative probe backoff. -The native watcher probes offline servers only on session activity, without an -idle polling timer. Coalesced events retain the first callback, and refresh runs -only when a turn has ended. Reasons remain pending until replacement. - -Readiness, adoption, and runtime publication are separate acknowledgments. -Native close uses bounded waits and can leave transport cleanup to owner-death -handling after forced connector termination. Do not interpret connector death -alone as confirmation that an external process has been reaped. Follow the +The watcher process in the same module probes offline servers only on session +activity, without an idle polling timer. Coalesced events retain the first +callback, and refresh runs only when a turn has ended. Reasons remain pending +until replacement. + +Readiness, adoption, and runtime publication are separate acknowledgments. Close +uses bounded waits and can leave transport cleanup to owner-death handling after +forced connector termination. Do not interpret connector death alone as +confirmation that an external process has been reaped. Follow the [shared lifecycle rules](contributing.md#preserve-extension-lifecycle-boundaries). +[`owned.gleam`](../src/albedo/harness/extensions/mcp/owned.gleam) starts the +connectors and the watcher. Each monitors the preparer and the runtime before it +initializes. Until the runtime adopts it, it answers only adoption and stop, and +its business messages stay queued. Only the runtime may adopt, and a repeated +adoption by the runtime succeeds. Adoption drops the preparer monitor; the +runtime's death still ends the process. `bundle.adopt` adopts the connectors in +order and then the watcher, stopping at the first refusal. `bundle.close` stops +them all within one shared deadline and is idempotent. Owned processes trap +exits, so a crashed dial or refresh worker settles its attempt, and killing a +connector also ends its linked workers. + +`endpoint.Seams` names the discovery, client transfer, and connector start +points that the [ownership tests](../test/harness/mcp_ownership_test.gleam) hold +or fail. Production passes `endpoint.seams()`. Drive new lifecycle tests through +the bundle's API and these seams, not through process internals. + ## Editor servers over ACP `editor-mcp` obtains the editor's session overlay and uses `editor_mcp` routes. diff --git a/test/e2e/areas.toml b/test/e2e/areas.toml index 3e7218096..28785d83a 100644 --- a/test/e2e/areas.toml +++ b/test/e2e/areas.toml @@ -347,6 +347,9 @@ "mcp_wire_test.py", "mcp_oauth_test.py", "acp_daemon_test.py", + # The editor overlay probe and the settings connection check. + "acp_test.py", + "settings_test.py", ] "robot-docs/mcp.md" = ["mcp_test.py", "mcp_ownership_test.py", "acp_test.py"] "src/albedo/anthropic_api/**" = [