feat(mcp): choose tool exposure automatically / 自动选择 MCP 工具暴露模式
Summary / 摘要
- Choose configured MCP exposure automatically at session boot; no new config or environment option.
- Keep small, cache-valid surfaces direct for low-latency concrete calls.
- Route large surfaces (at least 16 cached tools), oversized schema surfaces (16 KiB floor, scaled with the model context window), and missing/stale caches through the existing stable
use_capabilityproxy. - Freeze the choice for the session. Cache-miss discovery still runs in the background through a private registry, so it warms diagnostics and cache state without adding dynamic
mcp__*tools to the provider-visible registry.
在会话启动时自动决定配置 MCP 使用直接工具还是 use_capability 代理,不增加用户设置项;小型且缓存命中的工具面保持直连,大型、schema 过大或缓存未知的工具面自动使用稳定代理,并在整个会话内固定选择。
Required impact declarations
Documentation-impact: updated - documented automatic MCP exposure selection in English and Chinese.
Cache-impact: medium - large or unknown MCP surfaces receive a one-time stable proxy prefix; the decision is fixed for the session.
Cache-guard: go test ./internal/boot -run 'TestChooseMCPExposure|TestBuildAutomaticallyUsesCapabilityForLargeMCPSurface|TestBuildKeepsSmallMCPSurfaceDirect'
System-prompt-review: Codex review completed - no system-prompt text changes; only boot-time provider tool selection changes.
Why
Large MCP catalogs can consume a substantial provider tool prefix. A cache miss can also complete its handshake after boot and mutate the visible tool list. The automatic boundary keeps the ordinary path zero-configuration while preserving direct calls where their schema cost is small.
This adapts the MCP surface-collapse direction proposed by @bfxh in #7743. It intentionally does not include the user-facing meta-tool toggle or the unrelated long-horizon/navigation changes from that PR.
Refs #7743
Compatibility and cache impact
- Small configured MCP surfaces with matching caches keep the existing direct
mcp__*behavior. - Large or unknown configured surfaces receive one stable
use_capabilityschema instead of many MCP schemas. - The exposure decision is boot-scoped, so reconnects cannot change it mid-session.
- Explicit host-session MCP servers remain direct and session-scoped.
- Economy mode keeps its existing on-demand connector behavior.
- Upgrading can cause a one-time provider cache-prefix change when an existing MCP setup crosses the automatic boundary.
Verification
go test ./...go test -race ./internal/bootgo vet ./internal/boot ./internal/capability ./internal/plugin ./internal/agent- Integration coverage verifies large surfaces expose only
use_capability, small surfaces retain direct tools, and cold/stale caches choose the stable proxy while preserving background discovery diagnostics.