60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
46 lines
1.1 KiB
Plaintext
46 lines
1.1 KiB
Plaintext
---
|
|
title: Client Roots
|
|
sidebarTitle: Roots
|
|
description: Provide local context and resource boundaries to MCP servers.
|
|
icon: folder-tree
|
|
---
|
|
|
|
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.
|
|
|
|
## Static Roots
|
|
|
|
Provide a list of roots when creating the client:
|
|
|
|
```python
|
|
from fastmcp import Client
|
|
|
|
client = Client(
|
|
"my_mcp_server.py",
|
|
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",
|
|
roots=roots_callback
|
|
)
|
|
```
|