small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
6.7 kB · 122 lines
Markdown
at main

MCP extension #

The MCP extensions provide session-owned connections and expose discovered operations through Python. Configured servers and editor-provided servers have separate host routes but share the mcp binding. See MCP extension and Python binding.

Configure servers #

The mcp settings section accepts stdio and http servers. Stdio requires command and accepts args, cwd, and env. HTTP requires url and accepts headers and bearerTokenEnvVar. Environment and header values can be literal strings or environment references. Servers default to enabled. enabledTools and disabledTools select tools. Startup and call timeouts default to 20,000 and 60,000 milliseconds. Both must be positive and at most 3,600,000 milliseconds. retryMs defaults to 30,000. See server_decoder and config_section in extension.gleam.

Tools and lifecycle #

The configured extension requires python and prepares an owned managed contribution. It saves the last catalogue by server name and configuration fingerprint. An unavailable server produces a warning. The session can refresh when its catalogue changes. The host closes the connection when the contribution 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.

Server names, descriptions, and results are untrusted data. A failed or interrupted call may have had effects, so inspect those effects before retrying. A server-reported error appears in isError. A host failure raises McpError. See extension.gleam and mcp.py.

Catalogue policy and cache #

catalogue.gleam owns filtering, advertised identifiers, operation schemas, summaries, and context and Python definition rendering. Operations and summaries stay typed inside the runtime. Schemas retain the server's native JSON-compatible values without a JSON text round trip. Keep feature policy here and follow the shared contribution rules.

Tool and resource list failures fail discovery. Resource templates and prompt lists are optional and become empty on failure. Discovery preserves server order and permits at most 256 selected tools per server. The joined catalogue permits at most 512 operations and rejects duplicate advertised identifiers. Descriptions and resource identifiers are bounded untrusted text.

param_headers.gleam validates x-mcp-header annotations and converts call arguments to header values. HTTP discovery warns and excludes a tool with invalid annotations. Stdio discovery retains that tool without mirrored headers.

albedo_mcp_catalogue.erl reads and writes the existing version 2 external-term cache, converting its native maps at that boundary. Keep that saved shape compatible with existing catalogues. Native monitor, adoption, and cleanup mechanisms remain in albedo_mcp.erl and client.gleam.

Preparation and connection ownership #

preparation.gleam owns cached versus cold discovery and bundle sequencing. A thrown cache save closes the newly discovered client and earlier cold clients. Catalogue validation precedes watcher and connector allocation. A failed connector handoff closes completed connectors and clients still awaiting transfer.

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.

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 shared lifecycle rules.

Editor servers over ACP #

editor-mcp obtains the editor's session overlay and uses editor_mcp routes. Its overlay and catalogues live in daemon memory. The editor cannot reuse a configured server name. See editor_extension and prepare_editor in extension.gleam, and ACP.

The shared server configuration types live in sdk/editor_mcp. sdk/editor_overlay.resolve authorizes the marker and captures catalogue lookup/save operations for that revision. The attachment owner rejects a save after the overlay changes. Keep this captured capability through preparation rather than looking up a newer overlay halfway through it.

From Python #

await mcp.tools() lists operations, await mcp.search(query) ranks them, and await mcp.describe(name) returns a schema. await mcp.call(name, arguments) calls an advertised name or server/tool. The binding also mints mcp.<server>.<tool> methods from the catalogue at kernel boot. Operations added later or whose names cannot be minted remain reachable through call. See mcp.py.