Expand description
MCP client-roots adoption (opt-in, fallback-only).
Some hosts advertise the directory the user is working in via the MCP
roots capability — opencode does it on every connection. This module
consumes that advertisement so a server configured with
workspace.adopt_client_roots: true and no workspace.root can
bind the client’s directory instead of making the operator hand-write a
path the client already offered.
Three properties this module exists to preserve, in order:
- Fallback only. Anything the operator configured — manifest
workspace.root,--watch,--source-root,--workspace, or a runtimeset_root_dir— makes the workspaceRootOwnership::Operator, and adoption refuses to touch it. Forever, including across laterroots/list_changednotifications. - Contained. Adoption calls
Workspace::adopt_client_root, which is the same validate-canonicalize-contain-activate pathset_root_diruses. Aworkspace.sandbox_rootboundary therefore applies identically to a path proposed by an external party. The spec is explicit that roots are “informational guidance rather than an access-control mechanism” — the boundary is what contains them. - Invisible to everyone else. The guard chain is ordered
cheapest-first and exits before any I/O for a server that did not opt
in or a client that does not advertise
roots, so noroots/listrequest is ever put on the wire for such a client and no connect latency is added. The handler also runs on a task rmcp spawns, so even the opted-in path never delays the client’s session.
§Deprecated upstream
MCP roots is deprecated as of protocol revision 2026-07-28
(SEP-2577): “New implementations SHOULD NOT adopt it; existing
implementations SHOULD migrate to passing directories or files via tool
parameters, resource URIs, or server configuration.” It is eligible for
removal in the first revision released on or after 2027-07-28, and
that revision drops the server→client roots/list request and
notifications/roots/list_changed entirely.
This module is built anyway, deliberately: it is opt-in, so it costs
deployments that do not enable it nothing, and rmcp negotiates
2025-11-25, where the mechanism is live and fully implemented. The
migration path when it goes away is the one the spec names — pass the
directory via a tool parameter, a resource URI, or server configuration
(workspace.root).
Functions§
- file_
uri_ to_ path - Convert a
file://URI to a filesystem path.