当我的 Mac 里塞进 50 个 MCP 和 70 个 Skill:用“元工具”把上下文砍掉 90%

先看结论与实测战果

不讲宏大叙事,先摆在这台 Mac 上的真实运行数字:

  • System Prompt 底座常驻开销:从 14,500 Tokens 骤降至 ~1,200 Tokens(降幅 91.7%)。
  • 工具调用冲突与模型选错率:由原本 50+ 工具平铺时的 ~18% 错选/幻觉,降为 0 次错选。
  • Prompt Cache(前缀缓存)命中率:从过去“增删一个工具或修改一行技能全盘失效”,提升至日常长对话 92% 以上稳定缓存命中,模型响应首字延迟降低约 60%,API 费用省下大半。
  • 单机 RTK 截流收益:针对终端输出膨胀,联动 RTK 智能截流,本机累计 25,558 次命令已从源头挡掉 530 万 Tokens(平均每次截流 35.7%)。

一句话:我们把 50 多个 MCP 工具(含 Apple 官方 54 个 Xcode 工具)和 70 多个本地 Agent Skills,全部抽象进了两层“元工具 (Meta-Tools)”,让 AI 在需要时自己去查、去调,用完即走。


一、 惨剧:工具与技能是怎么撑爆模型的?

在日常深度用 AI 辅助全栈开发和 macOS 原生开发的过程中,我们本地的环境很快膨胀成了这样:

  1. MCP 工具暴增:
    接入 Apple 官方刚开放的 Xcode MCP 插件(PR #6338,通过 xcrun mcpbridge 连接),一口气挂上了 54 个编译、预览、UI交互、模拟器管理工具;再加上 Git、Exa 搜索、文档检索等,总工具数突破 60 个。
    • 后果:大模型标准的 Function Calling 要求把所有工具的 JSON Schema 全量塞进每一轮提示词。60 个工具平铺开,一句话没聊,8,000+ Tokens 已经蒸发了。
  2. Agent Skills 泛滥:
    本地积累了 70+ 个场景技能(从飞书 20+ 个办公工具、iOS 设计规范,到虚幻引擎 Unreal MCP、专利交底书撰写)。DSH 等 Agent 框架默认会把所有 Skill 的名称和功能简介生成一个目录塞进 System Prompt。
    • 后果:又是 3,500~4,000 Tokens 凭空消失。
  3. 终端回显轰炸:
    好不容易开始干活,一次 git diff、一个编译测试日志,哗啦啦几百行输出灌进窗口,单次上下文瞬间被撑大上万 Tokens。

结果就是:对话刚聊五六轮,上下文窗口就告急;每一轮即使只发一个字,也得为这上万字的固定“工具底座”反复付费。


二、 MCP 解法:用 mcp-meta 替代全量平铺

大模型其实根本不需要在第 1 轮就知道“修改 String Catalog 翻译文件的第 4 个入参叫什么”。

我们改变了思路:给模型一把钥匙,而不是把仓库里的所有零件挂在它胸口。

我们在本地 Magpie / MCP-Hub 体系中落地了 mcp-meta 代理层:

  • 模型常驻可见的工具面只有两个:
    1. mcp_tools(server):查询指定服务具备哪些能力。
    2. mcp_call(server, tool, args):派发具体的工具调用。
1
2
3
4
5
6
7
8
9
10
[ 用户提需求: "帮我编译当前 Xcode 项目并跑测试" ]
│
▼
[ Agent 查看工具面: 只有 mcp_tools 和 mcp_call ]
│
├─ 1. mcp_tools({ server: "xcode" })
│ └── 动态取回 Xcode 相关的极简接口清单 (BuildProject, Test...)
│
└─ 2. mcp_call("xcode", "BuildProject", { ... })
└── 后端透明转发至 xcrun mcpbridge,完成执行

成效:
54 个 Xcode 工具 + 其它外部 MCP 的海量 JSON Schema 全部退到幕后,常驻 Schema 开销从 8,000+ Tokens 降到 350 Tokens。


三、 Skill 解法:拒绝一刀切,走向“核心常驻 + 长尾懒加载”

技能能不能也照搬元工具?我们尝试过把 70 多个 Skill 全部彻底隐藏,做成纯懒加载。

但很快踩了坑:Agent 的主动嗅觉被阉割了。
当你要它改一段业务代码时,它根本想不起来要去调用“交付门禁(delivery-gates)”或者去翻“Obsidian 跨项目长期记忆库”。你必须像教小孩一样,每次都在 Prompt 里手敲“请使用某某技能”。

因此,我们设计了分层加载策略:

1. Tier 1 核心常驻层(严格控制在 5~6 个)

  • 工程门禁与底座:delivery-gates(不准自签完成)、obsidian-knowledge-base(记忆库只读查询)、retro(复盘)。
  • 当前核心业务栈:ios-design / ios-design-system。
  • 开销:控制在 ~400 Tokens,确保绝对不会挤占窗口,同时守住工程红线与核心直觉。

2. Tier 2 长尾按需层(65+ 个)全部归入 skill-meta

  • 飞书全家桶(20+ 个):lark-approval、lark-base、lark-doc、lark-wiki……
  • 垂直/偶发技能:虚幻引擎、专利写作、Office 文档精细排版、CI 提速体检等。
  • 机制:通过 skill-meta search 按语义检索长尾技能,或在用户提及“飞书打卡/导出PPT”时动态唤醒。

这一招把 Skills 的常驻目录开销直接抹去了 85%。


四、 终端截流:把 RTK 融入 Agent 肌肉记忆

工具和技能收束后,上下文里最大的动态垃圾就是 终端命令的冗长输出(占活跃窗口 59%)。

在 Codex 或 Claude Code 里,官方提供了底层 PreToolUse 钩子,可以通过 rtk hook 自动拦截并过滤命令。但在 DSH 或其他原生直接调用 bash -c 的 Agent 框架中,没有现成的底层钩子。

我们直接把规则刻进了全局工作纪律 ~/.dsh/AGENTS.md:

RTK 智能截流提速(全机统一标准):高回显命令优先使用本机全局 rtk 过滤代理(如 rtk git status/diff、rtk pnpm/cargo test、rtk xcodebuild、rtk err <cmd>),从源头削减巨量日志,保护上下文空间与执行速度。

实际跑下来,Agent 在需要排查 diff 或看测试报错时,会条件反射般执行:

1
2
rtk git diff
rtk err xcodebuild test -workspace MyApp.xcworkspace

单机 2.5 万次命令实测截流了 530 万 Tokens,彻底解决了长输出爆上下文的问题。


五、 架构全貌

现在的单机 Agent 运行时架构如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
┌────────────────────────────────────────────────────────────────────────┐
│ 本机 Agent (DSH / Claude Code) │
└───────────────────────────────────┬────────────────────────────────────┘
│
┌───────────────────────────────┼──────────────────────────────┐
▼ ▼ ▼
【常驻核心基底】 【mcp-meta 元工具】 【skill-meta 懒加载】
• 原生工具 (bash, read, edit) • mcp_tools(server) • 核心 6 技能常驻
• AGENTS.md 工程红线 • mcp_call(server, tool) • 65+ 长尾技能按需唤醒
• RTK 终端输出智能截流 │ │
▼ ▼
[ 54个 Xcode 工具 ] [ 飞书/Office/专利/UE ]
[ Git / Exa / 文档]

总结

大模型时代,很多人的直觉是“把所有能给的能力一次性全塞给它”。但在工程落地中,无限堆砌工具的结果不是变得全能,而是瘫痪与昂贵。

让绝大多数工具和技能退到幕后,以“元工具”按需索引,守住静态前缀保护 Prompt Cache。把真正宝贵、干净的上下文空间,留给你的代码、架构和思考。

Results and Hard Numbers First

No buzzwords. Here are the verified metrics from our Mac developer environment:

  • System Prompt Base Overhead: Slashed from 14,500 Tokens to ~1,200 Tokens (91.7% reduction).
  • Tool Selection Collisions / Hallucinations: Dropped from ~18% misfires when 50+ tools were flat-listed to 0 misfires.
  • Prompt Cache Hit Rate: Boosted from near-zero stability (invalidated by any minor tool/skill tweak) to >92% consistent cache hits across extended sessions, slashing TTFT by ~60% and cutting API billing dramatically.
  • Terminal Truncation Gains via RTK: Integrated RTK command filtering, saving over 5.3 Million Tokens across 25,558 executed bash commands (averaging a 35.7% token reduction per call).

In short: We abstracted 50+ MCP tools (including Apple’s 54 official Xcode tools) and 70+ local Agent Skills into two elegant “Meta-Tools”, allowing the AI to discover, invoke, and discard capabilities purely on demand.


1. The Bottleneck: How Tools and Skills Bloat the Context Window

As we integrated AI deeper into full-stack and native macOS development, our environment expanded rapidly:

  1. Explosion of MCP Tools:
    Enabling Apple’s official Xcode MCP bridge (xcrun mcpbridge, Anthropic PR #6338) added 54 tools overnight (build, test, canvas preview, string catalog edits, UI automation). Along with Git, Exa Search, and docs, we had over 60 active tools.
    • Cost: Standard Function Calling requires full JSON schema declarations for every tool in every single turn. Flat-listing 60 tools consumed 8,000+ Tokens before a single word was typed.
  2. Proliferation of Agent Skills:
    Our local catalog grew to 70+ skills (20+ Lark/Feishu integration skills, iOS UI design guidelines, Unreal Engine MCP skills, patent drafting, office automation). Most harnesses dump the entire summary catalog into the System Prompt.
    • Cost: Another 3,500–4,000 Tokens vanished into thin air.
  3. Verbose Terminal Logs:
    A single git diff or verbose compiler output would flood the active context with thousands of unnecessary tokens.

The consequence: Context limits were hit within 5–6 turns, and every trivial question cost a fortune due to re-sending the massive tool payload.


2. The MCP Solution: Replacing Flat Lists with mcp-meta

An LLM does not need to know the fourth argument of a localization catalog tool on Turn 1.

Our core insight: Give the agent a key to the tool shed instead of strapping 60 power tools to its back.

We introduced mcp-meta within our local Magpie / MCP-Hub infrastructure:
The agent sees only two universal tools:

  1. mcp_tools(server): Inspect available tools on a specific server.
  2. mcp_call(server, tool, args): Dispatch a structured execution.
1
2
3
4
5
6
7
8
9
10
[ User Prompt: "Build the current Xcode workspace and run unit tests" ]
│
▼
[ Agent sees minimal tools: mcp_tools and mcp_call ]
│
├─ 1. mcp_tools({ server: "xcode" })
│ └── Dynamically retrieves minimal schemas (BuildProject, Test)
│
└─ 2. mcp_call("xcode", "BuildProject", { ... })
└── Seamlessly forwarded to xcrun mcpbridge

Outcome:
Schemas for 54 Xcode tools and third-party MCP servers remain completely off-prompt until needed. Base tool overhead dropped from 8,000+ tokens to 350 tokens.


3. The Skills Solution: Tiered Architecture over Blind Lazy Loading

Can we do the same for Agent Skills? We tested a 100% lazy-loading approach for all 70 skills.

It immediately backfired: The agent lost its intuitive autonomy.
When asked to patch backend code, it forgot to enforce the delivery-gates verification protocol or query the obsidian-knowledge-base. The user had to manually instruct it: “Please load the delivery-gates skill first.”

To solve this, we implemented a two-tier architecture:

Tier 1: Core Pinned Skills (Strictly 5–6 items)

  • Engineering Baseline: delivery-gates (no self-signed completions), obsidian-knowledge-base (read-only permanent memory), retro (session reviews).
  • Active Focus: ios-design / ios-design-system.
  • Footprint: ~400 Tokens, safeguarding engineering boundaries and intuitive habits without bloating context.

Tier 2: Long-Tail On-Demand Skills (65+ items) via skill-meta

  • Collaboration Suites (20+ items): lark-doc, lark-approval, lark-base, lark-sheet…
  • Niche Workflows: Unreal Engine development, patent disclosure drafting, automated slide generation, CI speed audits.
  • Mechanism: Dynamically searched via skill-meta search or triggered contextually.

This sliced skill catalog overhead by 85%.


4. Terminal Log Truncation: RTK in Agent Muscle Memory

With tools and skills optimized, raw terminal stdout became the largest remaining token drain (59% of active tokens).

While tools like Codex and Claude Code feature native PreToolUse hooks for auto-wrapping commands with rtk, bare-metal bash execution engines lack pre-execution hooks.

We baked the protocol directly into our global rules (~/.dsh/AGENTS.md):

RTK Log Truncation (Machine Standard): High-verbosity commands must prioritize the local rtk proxy (e.g., rtk git status/diff, rtk pnpm/cargo test, rtk xcodebuild, rtk err <cmd>), pruning spam logs at the source to preserve context and speed.

Now, whenever inspecting diffs or build errors, the agent instinctively runs:

1
2
rtk git diff
rtk err xcodebuild test -workspace MyApp.xcworkspace

Over 5.3 million tokens have been saved across 25,500+ commands on this machine.


5. Final Architecture

The complete lightweight agent architecture:

1
2
3
4
5
6
7
8
9
10
11
12
13
┌────────────────────────────────────────────────────────────────────────┐
│ Host Agent (DSH / Claude Code) │
└───────────────────────────────────┬────────────────────────────────────┘
│
┌───────────────────────────────┼──────────────────────────────┐
▼ ▼ ▼
【Core Base】 【mcp-meta Engine】 【skill-meta Engine】
• Native bash, read, edit • mcp_tools(server) • 6 Core Pinned Skills
• AGENTS.md Guidelines • mcp_call(server, tool) • 65+ Long-Tail Skills
• RTK Terminal Interception │ │
▼ ▼
[ 54 Xcode Tools ] [ Lark / Office / UE ]
[ Git / Exa / Docs ]

Conclusion

In the age of LLMs, the naive instinct is to feed the model everything upfront. In real-world engineering, dumping all tools into context doesn’t make an agent omnipotent—it makes it confused, slow, and expensive.

Push tools and skills behind the curtain using meta-tool interfaces, and defend your static prompt prefix to maximize cache hits. Save your clean, precious context window for actual code, architecture, and reasoning.