zai-org / zai-org/feedback

[建议 / Feature] MCP 工具级启停(allowlist/denylist):按需裁剪工具定义,降低上下文占用

Open
#282 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2
Dominant language
No language data
Stars
22
Forks
1
PR merge metrics
No merged PRs in 30d

Description

提交前确认 · Pre-submission checklist
  • 我已搜索过现有 issue,确认这不是重复提议 / I searched existing issues and confirmed this isn't a duplicate.
  • 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.
问题类别 · Category
  • 工具调用 / MCP · Tool use / MCP
涉及的 Agent 框架 · Agent framework
  • ZCode Agent(自研)
使用场景 · Use case

我挂载了多个 MCP 服务器(如智谱视觉 @z_ai/mcp-server、Tavily、Jina 等),每个服务器启用后,它返回的全部工具定义(工具名 + 描述 + JSON Schema)都会随每次请求注入模型上下文。目前 ZCode 只有服务器级 enabled 开关,无法按工具裁剪。

实测:智谱视觉服务器 8 个工具的定义约 15–20KB(≈4–6K tokens/请求),我实际只用其中 1–2 个(analyze_imageextract_text_from_screenshot),其余 6 个每次请求白白占用上下文。

更严重的是性能问题:DeepSeek V4 Pro 0813 发布后的社区实验(dsh-anchored-standard 插件)显示,同一模型同一评测集,首轮全量注入 20+ 个工具得分 91;首轮只暴露 2 个工具、首次工具调用后再恢复全部,得分 98/99(均值 98.5)。推理过程也从 208 次 "let me" 的犹豫,变成 "we need" 的果断。官方 Harness 源码含 "sends the exact RL prompt and schemas" 测试文件,佐证模型对工具暴露环境存在 RL 过拟合(来源:新浪科技 2026-08-15 报道)。工具定义注入量是影响模型表现的直接变量,用户应当有权裁剪。

建议方案 · Proposal

在 MCP 服务器条目上新增工具级 allowlist/denylist 配置(缺省 = 全部启用,向后兼容):

"tools": {
  "mode": "allowlist",   // allowlist | denylist
  "list": ["analyze_image", "extract_text_from_screenshot"]
}

UI 层(设置 → MCP 管理)参考腾讯 WorkBuddy 的"MCP 服务管理":服务器卡片显示 "N/M 个工具已启用" 计数器,展开后每个工具一行开关,提供"全选/全不选/仅保留常用"快捷操作和工具名搜索过滤。

实现为纯客户端过滤tools/list 照常取全量,注入模型请求前按配置裁剪;无需改 MCP 协议,服务器无感知、无兼容性问题。

预期价值 · Expected value
  • 上下文:单服务器裁剪到 2 个工具省约 75% 工具定义开销(每请求 3–5K tokens);挂 3–4 个服务器时工具定义总量可达 20–40K tokens/请求;
  • 性能:对标锚定实验(91 → 98.5),对工具结构敏感的模型(如 DeepSeek V4 Pro 系)收益最明显;
  • 成本:输入 token 按量计费,静态开销下降直接省钱;
  • 可用性:工具减少后模型误选工具的概率下降,响应更聚焦。
你认为的优先级 · Your perceived priority
  • 高 · High
你使用的 ZCode 版本 / 环境 · ZCode version / environment

ZCode 3.7.7 (Windows x64)

补充材料 · Additional context
  • 参考产品:腾讯 WorkBuddy "MCP 服务管理"界面(服务器卡片 + 工具级勾选 + "36/38 个工具已启用"计数)
  • 实验来源:新浪科技 2026-08-15《DeepSeek V4 Pro正式版反转:真的很强 满血性能被束缚了》https://finance.sina.com.cn/tech/roll/2026-08-15/doc-ininkmqs1946801.shtml
  • 实测数据:@z_ai/mcp-server 8 个工具定义 ≈ 15–20KB(2026-08-16)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read CONTRIBUTING.md first, then locate the existing server-level enabled setting and the request path that injects tools/list results into model context. Review the Settings → MCP management entry point for the proposed tool controls. Done means allowlist/denylist filtering, counters and tool selection work while the default remains backward compatible.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.