All Agent Engineering

Connect MCP Roots Declarations to Real File Access Limits

Separate roots capability, file:// URI rules and server-side path checks into one boundary sheet.

AINavWritten / Updated
On this page

At a glance

In the MCP 2025-06-18 specification, Roots lets a client tell a server which directories it may work in. The page assigns MUST and SHOULD duties to both sides, but a declaration does not perform any path check for the server. This task maps client roots URIs to server file operations and produces a boundary sheet that states who handles notifications, URI types and execution-side validation.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • MCP Connect MCP Roots Declarations to Real File Access Limits

Execution locations and responsibilities

  • MCP client and server Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. Confirm the roots capability → 2. Read and record the roots list → 3. Check the URI type → 4. Validate every path at execution → 5. Handle list changes and unavailable roots → 6. File the boundary sheet. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. Confirm the roots capability2. Read and record the roots list3. Check the URI type4. Validate every path at execution5. Handle list changes and unavailable roots6. File the boundary sheet

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • A client that supports roots must declare the roots capability during initialization; listChanged says whether the client will emit notifications when the list changes. A server should check that the capability exists before using roots.

When not to use

  • A roots declaration describes scope only; the page does not say a server is stopped automatically from going outside it, so the block must be written into the server's file operations.
  • The page specifies only file://; other URI schemes, symbolic links and normalization details are not covered by the supplied text and must not be assumed guaranteed.
  • This task does not cover resource reads, tool calls or authorization, which belong to other topics.

Prerequisites and input

  • You have the roots a client exposes and the list of file operations the server performs.
  • You can tell which checks belong to the client and which must live in the server's file access code.

Engineering checks

Declaration layer: capability and change notices — A client that supports roots must declare the roots capability during initialization; listChanged says whether the client will emit notifications when the list changes. A server should check that the capability exists before using roots.

Data layer: URI type and list contents — Each root has a uri and an optional name. In the current specification the uri must be a file:// URI. The server fetches the list with roots/list; a client without support should return -32601, and internal errors use -32603.

Execution layer: who holds the boundary — Clients must expose only roots with appropriate permissions, validate root URIs against path traversal, apply access controls and monitor accessibility. Servers should respect root boundaries and validate all paths against the provided roots. The page gives no path normalization algorithm, so the implementer must define and record one.

1. Confirm the roots capability

Where: the client capabilities sent at initialization. Input: the declared capabilities. Action: confirm roots is present and note the listChanged value. Completion check: the sheet states whether the client promises change notifications. Stop condition: if roots is not declared, the server must not treat roots as a usable boundary and should report the missing boundary instead.

2. Read and record the roots list

Where: the server's request to the client. Input: the roots/list response. Action: record each uri and name. Completion check: every root has a matching record. Stop condition: -32601 means the client lacks support and -32603 is an internal error; do not guess a default directory in either case, halt file operations and report.

3. Check the URI type

Where: the server, after receiving roots and before using them. Input: each root's uri. Action: confirm it is a file:// URI. Completion check: every root admitted to the boundary set has that type. Stop condition: a URI of another type is not admitted; the page does not say how to handle it, so mark it as undecided on the sheet.

4. Validate every path at execution

Where: the server code that actually reads or writes files. Input: the requested path and the current roots set. Action: validate the path against the roots before each operation and watch for path traversal. Completion check: the sheet lists a validation point for each kind of file operation. Stop condition: if the path falls outside all roots or its ownership cannot be decided, reject the operation.

5. Handle list changes and unavailable roots

Where: the server's notification handling and cache. Input: notifications/roots/list_changed, or a root that stops being reachable. Action: on notification, request roots/list again and refresh the cache; let affected operations fail gracefully when a root is unavailable. Completion check: stale cache entries are no longer used for new operations. Stop condition: if listChanged is false, do not rely on notifications; the implementer decides and records when to re-read.

6. File the boundary sheet

Where: the team's design record. Input: conclusions from the previous five steps. Action: write down the owner of the declaration, URI type, validation points, change handling and open items. Completion check: every row has an owner and a stop reason. Stop condition: if any row lacks an owner, the sheet is not complete.

Task example

This is a hypothetical manual walkthrough, not a real run. Suppose the client declares roots with listChanged true and returns two repositories as file:// roots. The server is asked to read a path under neither root; step four says reject it and record why. The user then removes one repository, and the expected behavior is that the client sends notifications/roots/list_changed, the server re-reads the list, and paths under the removed repository are no longer accepted. All of this is an expected observation and has not been verified.

Completion checks

  • Capability check: does the sheet record the roots declaration and the listChanged value?
  • Type check: is every root that was adopted a file:// URI?
  • Execution check: does each file operation entry point validate against roots, and does it use the refreshed list after a change?

Verification scope

Written only from the supplied Roots page of the MCP 2025-06-18 specification. The documentation was read; installation, login, API execution and output were not tested.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. MCP · MCP documentation: mcp-roots

Found an error? Tell us →