MCP Context 效率革命:從全量載入到按需載入
深入分析 MCP 的 Context 消耗問題,以及社群提出的兩個解決方案:Context Isolation 與 Progressive Disclosure
當你啟用 7 個 MCP 伺服器時,你的 Context 已經消耗了 33.7%——還沒開始工作。
這篇文章分享 Claude World Taiwan 社群對 MCP Context 效率問題的深度討論,以及我們提出的解決方案。
問題:MCP 的 Context 消耗
我們實測了常見 MCP 伺服器的 Token 消耗:
| MCP 伺服器 | Token 消耗 |
|---|---|
| GitHub (27 tools) | ~18,000 |
| AWS MCP servers | ~18,300 |
| Cloudflare | ~15,000+ |
| Sentry | ~14,000 |
| Playwright (21 tools) | ~13,647 |
| Supabase | ~12,000+ |
| 7 個伺服器合計 | 67,300 (33.7%) |
平均每個 Tool 消耗 550-850 tokens。
現代知識工作者的困境
我們同時使用多個平台:GitHub、Jira、Linear、Slack、Vercel、Sentry…
這造成一個兩難選擇:
- 全部安裝:Session 開始就消耗 50%+ Context
- 依專案分開:失去 Claude Code 作為統一指揮中心的價值
解決方案一:Context Isolation(RFC 提案)
我們向 Anthropic 提交了 RFC #17668,提出 Context Isolation 架構。
核心概念
不同於傳統 Lazy Loading,Context Isolation 的關鍵差異:
| 方面 | 傳統 Lazy Loading | Context Isolation |
|---|---|---|
| Main Context | 需要時載入,會污染 | 永遠保持乾淨 |
| 載入時機 | 運行時動態載入 | Fork 建立時載入 |
| 複雜度 | 高(狀態管理) | 低(複用 context: fork) |
架構設計
Main Session(精簡)
│
├── 基礎 MCP:filesystem, memory
│ (最小 context 佔用)
│
├── Task: database-specialist(forked)
│ └── 載入:postgres, redis(隔離)
│
└── Skill: /deploy(forked)
└── 載入:vercel, github(隔離)
實作方式
MCP 端:settings.json 新增 lazy 標記
{
"mcpServers": {
"memory": { "command": "...", "lazy": false },
"github": { "command": "...", "lazy": true },
"postgres": { "command": "...", "lazy": true }
}
}
Agent/Skill 端:frontmatter 宣告需要的 MCP
---
name: database-specialist
description: 資料庫操作專家
tools: [Read, Bash, Grep]
mcp:
required: [postgres]
optional: [redis]
context: fork
---
為什麼選擇 MCP 而非純 Script?
MCP 的價值不只是 Tools,更重要的是集中式認證管理:
| 面向 | MCP | Scripts + .env |
|---|---|---|
| 憑證管理 | 集中在 settings.json | 分散各處 |
| 安全性 | 環境隔離 | 可能洩漏在 logs |
| Token 刷新 | 自動處理 | 需手動實作 |
| 錯誤處理 | 標準化回應 | 各 API 不同 |
解決方案二:Progressive AgentSkill(社群開源)
社群成員 CabLate 開發了 mcp-progressive-agentskill,實作三層漸進式揭露:
三層架構
- 第一層:列出可用 MCP 伺服器(~50-100 tokens)
- 第二層:顯示選定伺服器的 Tool 名稱與描述(~200-400 tokens)
- 第三層:載入完整 Tool 規格(~300-500 tokens/tool)
效益計算
假設一個 MCP 有 20 個 Tools,你只需要 2 個:
| 方式 | Token 消耗 |
|---|---|
| 傳統全量載入 | ~6,000 tokens |
| 漸進式揭露 | ~850 tokens |
| 節省 | 86% |
技術架構
AI Scripts (Python) → HTTP API → MCP Daemon → MCP Servers
Daemon 維持長連接,提供 HTTP 介面按需存取 Tool 資訊。
快速開始
# 安裝
python scripts/setup.py
# 啟動 Daemon
python scripts/daemon_start.py --no-follow
# 列出 Tools
python scripts/mcp_list_tools.py --server playwright
# 呼叫 Tool
python scripts/mcp_call.py --server playwright --tool browser_navigate \
--params '{"url":"https://example.com"}'
現階段建議
在官方支援 Context Isolation 之前,我們建議:
1. 分類你的 MCP
必要(lazy: false):
- filesystem
- memory
- sequential-thinking
重型(考慮移除或等待 lazy):
- github(18k tokens)
- aws(18k tokens)
- sentry(14k tokens)
2. 使用 Project Scope
# 只在需要的專案啟用特定 MCP
claude mcp add --scope project postgres -- ...
3. 嘗試 Progressive AgentSkill
對於重度 MCP 使用者,CabLate 的方案可立即使用。
參與討論
- RFC Issue: #17668 - 歡迎 👍 支持
- 開源專案: mcp-progressive-agentskill
- 社群討論: Discord - Claude World Taiwan
這篇文章整理自 Claude World Taiwan 社群的技術討論。我們是一群專注於 Claude Code 進階使用的開發者,歡迎加入我們的 Discord 一起交流。