What are roots and sampling used for?
Model Context Protocol (MCP) defines separate workflows for roots and sampling between a client and a server. Roots let the client tell the server where it can work in the file system. Sampling lets the server request output from a language model through a client.
Under the MCP roots specification, a server can request the list of roots from a client that supports the feature. It can also receive a notification when the list changes. A root helps the server understand which directories and files it can access in the file system.
Under the MCP sampling specification, the client retains control over model access, model selection, and permissions. The server can request interactions involving text, audio, or images. It can also choose to include context from MCP servers in the prompt.
How is the list of roots exposed?
MCP notes that roots are typically exposed through workspace or project configuration interfaces. An application can provide a workspace or project picker so users can choose which directories and files the server can access. The application can combine this selection with automatic workspace detection based on version control systems or project files.
The protocol leaves the choice of user interface for roots to each application. Applications can use a layout that suits their needs. How users manage roots depends on the layout the application chooses.
A client that supports roots must declare the roots capability at the start of the connection. The listChanged field in that capability indicates whether the client will send a notification when the list of roots changes. Its value indicates support for change notifications. The list itself is provided separately.
The server sends a roots/list request to retrieve the list. In MCP's example request, the method field is set to roots/list. In the client's response, root definitions appear in the roots field within result.
The uri in a root definition is the root's unique identifier. The MCP roots specification requires it to be a file:// URI. The optional name field provides a human-readable name for display. The name and URI are separate fields in the definition.
A root can point to a single project directory. The list can also contain separate root definitions for multiple repositories. In MCP's example, the frontend and backend repositories each have their own URI and name.
When the roots change, a client with listChanged support must send a notifications/roots/list_changed notification. This tells the server that the list has changed. The roots/list request retrieves the list, while notifications/roots/list_changed is a separate message that reports a change.
Permissions and error cases for roots
MCP's roots security rules require the client to expose only roots with appropriate permissions. The client must also validate all root URIs to prevent path traversal, apply appropriate access controls, and monitor root availability.
MCP recommends that the client ask for user approval before exposing roots to the server. Other implementation recommendations include providing clear interfaces for managing roots, checking their availability before exposing them, and monitoring changes.
On the server side, MCP recommends respecting root boundaries during operations and validating all paths against the roots the client exposes. It also calls for servers to handle roots that become unavailable. The implementation guidance includes checking capability support before using roots and caching root information as appropriate.
If the client does not support roots, it can return a standard JSON-RPC error response. MCP lists unsupported methods and internal errors as common examples. In the example error response, error contains code, message, and data fields. The data field can include a reason indicating that the client does not support the roots capability.
How does a sampling request work?
In MCP's sampling workflow, the server initiates the request. It sends a sampling/createMessage request to the client to ask a language model to generate output. A client that supports sampling must declare the sampling capability at the start of the connection.
Sampling allows model calls to be embedded in other MCP server features. MCP notes that this mechanism lets servers implement agentic behavior. As with roots, the protocol leaves the choice of user interface for sampling to each application.
For trust and safety, MCP recommends keeping a human in the loop who can reject a sampling request. It also recommends that applications provide an interface that makes sampling requests easy to review. The same interaction model lets users view and edit prompts before they are sent and review generated responses before delivery.