Back to Fastmcp

Client Roots

docs/clients/roots.mdx

4.0.0a11.4 KB
Original Source

import { VersionBadge } from '/snippets/version-badge.mdx'

<VersionBadge version="2.0.0" />

Use this when you need to tell servers what local resources the client has access to.

Roots inform servers about resources the client can provide. Servers can use this information to adjust behavior or provide more relevant responses.

<Note> **Roots require the older MCP protocol.** A server reads roots by sending a request down to the client, and protocol version `2026-07-28` removed the server's ability to do that. Clients default to `mode="auto"`, which negotiates the newest version both sides support, so the examples below pass `mode="legacy"`. See [protocol negotiation](/clients/client#protocol-negotiation). </Note>

Static Roots

Provide a list of roots when creating the client:

python
from fastmcp import Client

client = Client(
    "my_mcp_server.py",
    mode="legacy",
    roots=["/path/to/root1", "/path/to/root2"]
)

Dynamic Roots

Use a callback to compute roots dynamically when the server requests them:

python
from fastmcp import Client
from fastmcp.client.roots import RequestContext

async def roots_callback(context: RequestContext) -> list[str]:
    print(f"Server requested roots (Request ID: {context.request_id})")
    return ["/path/to/root1", "/path/to/root2"]

client = Client(
    "my_mcp_server.py",
    mode="legacy",
    roots=roots_callback
)