Skip to content

Feat/run mcp meta tool - #7743

Open
bfxh wants to merge 5 commits into
esengine:main-v2from
bfxh:feat/run-mcp-meta-tool
Open

Feat/run mcp meta tool#7743
bfxh wants to merge 5 commits into
esengine:main-v2from
bfxh:feat/run-mcp-meta-tool

Conversation

@bfxh

@bfxh bfxh commented Aug 6, 2026

Copy link
Copy Markdown

Cache-impact: low - use_capability proxy has fixed Schema() and static Description(); no change to cache prefix calculation or invalidation logic.
Cache-guard: go test ./internal/config/ ./internal/plugin/... ./internal/boot/ ./internal/agent/
System-prompt-review: No system_prompt_file modified.
Documentation-impact: updated - docs/META_TOOL.md added with full config usage, priority resolution, and verification instructions.

Summary

Collapse the MCP tool surface behind the existing use_capability proxy (meta-tool mode):

  • [tools] meta_tool = true / REASONIX_MCP_META_TOOL=1 hides all top-level mcp__<server>__<tool> entries and registers the use_capability proxy. Real boot.Build measurement (reviewer-verified): baseline 122 tools / 75 mcp__ top-level / 63353 bytes -> meta-tool 48 tools / 0 mcp__ top-level / 54189 bytes (tools -60.7%, bytes -14.5%).
  • Runtime identity isolation via MCPRuntimeSpecMatches: same-name servers with different specs cannot cross-discover or cross-call.
  • No direct tools/call bypass: permission gate, Pre/PostToolUse hooks, evidence, and destructive/readOnly checks run against the real mcp__<server>__<tool> name via the existing CallResolver flow.
  • Lazy startup: cache hits do not start processes; fixed Schema()/Description() stable across connection drift and hot-add.
  • CodeQL: build-error logging redacted (CWE-532 clear-text logging).

Issues

Verification

  • go build ./... -> ok
  • go test ./internal/config/ ./internal/plugin/... ./internal/boot/ ./internal/agent/ -> all ok
  • gofmt -l clean; git diff --check clean
  • mcp-surface-dump real boot.Build measurement: 122 -> 48 tools, 75 -> 0 mcp__ top-level, 63353 -> 54189 bytes

Documentation impact

Documentation-impact: updated - docs/META_TOOL.md added with full config usage, priority resolution, and verification instructions.

Cache impact

Cache-impact: low - use_capability proxy has fixed Schema() and static Description(); no change to cache prefix calculation or invalidation logic.
Cache-guard: go test ./internal/config/ ./internal/plugin/... ./internal/boot/ ./internal/agent/
System-prompt-review: N/A - no system_prompt_file modified; use_capability is a tool-level proxy, not a system prompt change.

@bfxh
bfxh requested review from SivanCola and esengine as code owners August 6, 2026 09:21
@github-actions github-actions Bot added agent Core agent loop (internal/agent, internal/control) v2 Go rewrite (1.x) — main-v2 branch, active development mcp MCP servers / plugins (internal/plugin, codegraph) config Configuration & setup (internal/config) labels Aug 6, 2026

Copy link
Copy Markdown
Collaborator

感谢实现这个方向。MCP meta_tool 部分我认为是有意义的:我在当前分支复跑 go run ./cmd/mcp-surface-dump,得到工具条目 122→48、顶层 mcp__ 75→0,tools 数组字节 63,353→54,189;固定 schema、spec 身份隔离和 lazy startup 也解决了原 per-tool surface 的实际问题。

不过在合并整个 PR 前,我建议先拆分或补齐以下问题:

  1. Navigator 目前似乎没有接入生产工具调用路径。boot 中构造了 navKernel,但仓库里没有 navKernel.Execute(...)/ navigator.Execute(...) 的调用;run_loop.go 实际只调用 StateTracker 的 BeforeToolCall/AfterToolCall。因此 Navigator 声称的 closed-loop correction、环境感知和回滚目前不会发生。若接入,需要确保不绕过 Agent 现有的 permission/hooks/evidence 流程。
  2. verification_interval 目前只有配置和启动诊断,没有运行时的 verification nudge;文档中的“下一阶段实现”说明了这一点。
  3. run_loop.go 调用 AfterToolCall(..., nil),真实工具错误没有传给 StateTracker,失败调用可能被记录为成功。
  4. StateTracker 的 implicit facts 没有容量上限,也没有跨调用去重;长任务中可能不断膨胀,并在每次压缩时重复注入。
  5. long_horizon = false 时,StateTracker 和 10-section compaction prompt 仍然被无条件启用,但 boot 诊断却显示“7 sections / no implicit-state capture”,开关语义和实际行为不一致。

我本地运行了 go test ./...,测试全部通过;但目前新增测试主要是单元测试,缺少 boot→Agent→实际工具调用的 Navigator 集成测试。

建议把成熟的 MCP meta_tool 先独立合入,把 Navigator/long-horizon 状态增强拆成后续 PR,或者先补齐上述接入和边界问题。

Comment thread cmd/mcp-surface-dump/main.go Outdated
fmt.Println("=== use_capability registered: YES (single proxy replaces all mcp__ entries) ===")
}
if meta.buildErr != nil {
fmt.Printf("\n[meta-tool build error: %v]\n", meta.buildErr)
Comment thread cmd/mcp-surface-dump/main.go Outdated
fmt.Printf("\n[meta-tool build error: %v]\n", meta.buildErr)
}
if baseline.buildErr != nil {
fmt.Printf("\n[baseline build error: %v]\n", baseline.buildErr)
Comment thread cmd/mcp-surface-dump/main.go Outdated

func printRow(s surface) {
if s.buildErr != nil {
fmt.Printf("%-22s BUILD FAILED: %v\n", s.mode, s.buildErr)
lbx13 added 5 commits August 6, 2026 21:39
Replace every per-tool mcp__<server>__<tool> top-level entry with a
single run_mcp dispatcher, shrinking the provider's tools array from
114 to 20 entries (82.5% drop) on a 19-server config.

Three-layer config resolution: env REASONIX_MCP_META_TOOL overrides
[tools] meta_tool config, which defaults to false (legacy behavior
unchanged).

- metatool.go: run_mcp dispatcher with dynamic server-to-tool mapping in
  Description(), cache-backed first-turn fallback, ImageTool support
- config.go: ToolsConfig.MetaTool *bool + MCPMetaToolEnabled() resolver
- boot.go: meta-tool mode branch in registerBackground + diagnostic Notice
- cmd/mcp-surface-dump: real boot.Build comparison (config-file path)
- cmd/meta-tool-priority: 39-case env x config priority matrix demo
- Tests: description contract, capacity math, schema validation,
  24-case config/env priority matrix
- META_TOOL.md: usage documentation
The docs-impact check requires docs/*.md changes when Documentation-impact
is "updated". Moving META_TOOL.md from repo root to docs/ satisfies this
requirement.
Meta-tool mode now hides every mcp__<server>__<tool> top-level entry and
registers the existing use_capability proxy instead of a second dispatcher:

- Runtime identity isolation via MCPRuntimeSpecMatches (same-name servers
  with different specs cannot cross-discover or cross-call).
- No direct tools/call bypass: ResolveCall resolves to the real
  mcp__<server>__<tool> name, so CallResolver runs the permission gate,
  Pre/PostToolUse hooks, evidence, and destructive/readOnly checks.
- Lazy startup: use_capability returns deferred Targets that connect on
  demand; cache hits do not start processes.
- Fixed Schema() and static Description() - stable across connection drift.
- Deleted run_mcp implementation (metatool.go -> env-only shim, metatool_test.go removed).
- boot.go: capRuntime/capLedger build when meta-tool enabled; tool-surface
  diagnostic reports use_capability registration.

Implicit-state diagnostics (compact.go / long_horizon_test.go) stay in the
long-horizon branch and are not part of this PR.
… mcp-surface-dump

Boot/config errors can embed provider API keys (CWE-532 clear-text
logging). redactErr masks sk-*, api key/token/secret/password patterns
before they reach stdout.
@bfxh

bfxh commented Aug 6, 2026

Copy link
Copy Markdown
Author

感谢详细评审,已按建议拆分并补齐:

本 PR(#7743)现在只含 meta_tool,5 个 commits:

  1. feat(meta-tool): collapse MCP tool surface to single run_mcp dispatcher
  2. chore(docs): move META_TOOL.md to docs/
  3. refactor(meta-tool): replace run_mcp with use_capability proxy(对应上轮 Feat/run mcp meta tool #7577 评审的全部阻塞项:spec 身份隔离 / CallResolver 安全流 / lazy startup / 固定 schema / 复用 use_capability)
  4. style: gofmt alignment fixes
  5. fix(codeql): redact build-error logging(新增,处理 CodeQL CWE-532)

Navigator / long-horizon / StateTracker 已拆出feat/long-horizon-navigator 分支(保留全部 commits),将作为后续独立 PR 提交。您列的 5 个接入问题(navKernel 未接入 run_loop、verification_interval 无运行时 nudge、AfterToolCall 传 nil、facts 无容量上限/去重、long_horizon=false 时开关不一致)会在那个 PR 中处理后再提交。

关于复测数据:122→48 tools / 75→0 mcp__ / 63353→54189 bytes 与本分支最终状态一致(已写入 PR body)。

CodeQL 的 3 处明文日志已修复:cmd/mcp-surface-dump/main.go 新增 redactErr,sk-*/api key/token/secret/password 模式脱敏后再打印。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Core agent loop (internal/agent, internal/control) config Configuration & setup (internal/config) mcp MCP servers / plugins (internal/plugin, codegraph) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants