MCP Specification · 2026-07-28 · zh-TW
Roots(根目錄)
Roots · Deprecated
Client 向 server 提供相關檔案與目錄位置的既有 informational guidance;2026-07-28 已棄用。
Roots 自 MCP 2026-07-28 起已棄用。新實作 SHOULD NOT(不應)採用;既有實作 SHOULD(應該)改用 tool parameters、resource URIs 或 server configuration 傳遞檔案與目錄資訊。
Roots 是讓 MCP client 向 server 暴露「與目前工作相關的檔案系統位置」的既有機制。Roots 只提供資訊性 guidance,不是 access-control mechanism;協定不會強制 server 只能在 roots 內操作。
使用者互動模型(User Interaction Model)
Roots 通常透過 workspace / project 設定呈現,例如讓使用者選擇 server 應該關注的目錄或檔案,也可以搭配版本控制或 project file 自動偵測。協定本身不強制特定 UI。
能力宣告(Capabilities)
仍支援 roots 的 client MUST(必須)在每個 request 宣告:
{
"_meta": {
"io.modelcontextprotocol/clientCapabilities": {
"roots": {}
}
}
}
列出 Roots(Listing Roots)
Server 若在處理原始 client request 時需要 roots,會回 InputRequiredResult,並在 inputRequests 中放入 roots/list:
{
"method": "roots/list"
}
Client 取得資料後,在 MRTR 重試 request 的 inputResponses 回傳:
{
"roots": [
{
"uri": "file:///home/user/projects/myproject",
"name": "My Project"
}
]
}
訊息流程(Message Flow)
- Client 送出原始 request,例如
tools/call。 - Server 回
InputRequiredResult(roots/list)。 - Client 取得 roots 後,以新的 JSON-RPC request ID 重試原操作,帶上
inputResponses與必要的requestState。
Root 資料型別(Root Data Type)
每個 root 包含:
uri:root 的唯一識別碼;本版規範中 MUST(必須)是file://URI。name:選用的人類可讀顯示名稱。
[
{
"uri": "file:///home/user/repos/frontend",
"name": "Frontend Repository"
},
{
"uri": "file:///home/user/repos/backend",
"name": "Backend Repository"
}
]
錯誤處理(Error Handling)
若取得 roots 時發生錯誤,client 不必為了回報 error 而重播原始 request;InputRequiredResult 並不是 server 同步等待回覆的 pending call。
安全考量(Security Considerations)
Client MUST(必須):
- 只暴露具有適當 permission 的 roots。
- 驗證所有 root URI,避免 path traversal。
- 實作正確的 access controls,並監控 root 是否仍可存取。
Server SHOULD(應該):
- 處理 root 失效或無法存取的情況。
- 在操作時尊重 root boundary,並驗證 path 是否落在提供的 roots 內。
上述 server 行為是 implementation guidance;MCP protocol 本身不會阻止 server 存取 root 之外的位置,因此實際權限仍必須由 OS、sandbox、container、permission model 或 server 自己的安全控制實施。
實作指引(Implementation Guidelines)
Client SHOULD(應該)在暴露 roots 前取得使用者同意、提供清楚的 root management UI、先確認位置可存取,並持續監控 root changes。Server SHOULD(應該)在使用前確認 client 宣告 roots capability、操作時尊重 root boundaries,並適當 cache root information。