Roots 是 MCP 中的一个概念,它定义了 servers 可以操作的边界。它们为 clients 提供了一种方式,可以告知 servers 有关相关 resources 及其位置的信息。Documentation Index
Fetch the complete documentation index at: https://mcp-docs.cn/llms.txt
Use this file to discover all available pages before exploring further.
什么是 Roots?
一个 root 是一个 URI,client 建议 server 应该关注它。当 client 连接到 server 时,它声明 server 应该使用哪些 roots。虽然主要用于文件系统路径,但 roots 可以是任何有效的 URI,包括 HTTP URL。 例如,roots 可以是:为什么要使用 Roots?
Roots 有几个重要的用途:- 指导: 它们告知 servers 有关相关 resources 和位置的信息
- 清晰: Roots 明确了哪些 resources 是你的 workspace 的一部分
- 组织: 多个 roots 允许你同时使用不同的 resources
Roots 如何工作
当 client 支持 roots 时,它:- 在连接期间声明
rootscapability - 向 server 提供建议的 roots 列表
- 在 roots 更改时通知 server (如果支持)
- 尊重提供的 roots
- 使用 root URIs 来定位和访问 resources
- 优先考虑 root 边界内的操作
常见用例
Roots 经常用于定义:- 项目目录
- 仓库位置
- API endpoints
- 配置位置
- Resource 边界
最佳实践
在使用 roots 时:- 仅建议必要的 resources
- 为 roots 使用清晰、描述性的名称
- 监控 root 的可访问性
- 优雅地处理 root 更改