Skip to content

feat(agent-core-v2): add global default for deferred MCP tool disclosure - #4210

Merged
sailist merged 2 commits into
mainfrom
feat-289-10-14-mcp-default-deferred
Oct 14, 2026
Merged

sailist merged 2 commits into
mainfrom
feat-289-10-14-mcp-default-deferred

Conversation

@sailist

@sailist sailist commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

新增 [mcp] default_deferred 配置:控制 tool-select 模式下 MCP 工具默认全部 defer,还是按各 server 自己的 deferred 配置决定。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

默认值解析(唯一解释点,connected 与 needs-auth 共用,在 server (re)connect 时固化到 entry——与 timeout 系配置同一生效时机):

 resolved(server).deferred
-  = config.deferred === true
+  = entry.deferred                            # 连接时捕获,运行中不随 config.toml 变化
+  where entry.deferred (captured in connect/connectOne)
+  = config.deferred ?? defaults.defaultDeferred ?? false   # server 显式配置 > 全局默认 > false

 McpConnectionView
-  configOf(name)      -> 原始 server 配置(唯一调用者是 needs-auth 注册路径)
+  deferredOf(name)    -> 捕获后的布尔

配置下发链路(沿既有 tunables/resolver 模式):

 config.toml [mcp] default_deferred
   McpSectionSchema.defaultDeferred            # 新增 zod 字段,无 env 绑定
     workspaceMcpConfigService.tunables()
-      resolveDefaultTimeouts  ->  McpDefaultTimeouts
+      resolveDefaults          ->  McpDefaults (+ defaultDeferred)
        McpConnectionManager    # (re)connect 时 resolveDeferred 捕获到 entry
          ├─ resolved()            → AgentMcpService 注册 connected 工具
          └─ AgentMcpService       → 注册 needs-auth OAuth 合成工具

其他:docs/config-manifest.toml 由 gen:config-manifest 重新生成;docs/en|zh 的 config-files.md([mcp] 表)与 customization/mcp.md(deferred 字段行 + 按需加载一节,含生效时机说明)同步;McpDefaultTimeouts/resolveDefaultTimeouts 随承载新字段更名为 McpDefaults/resolveDefaults(影响面核实限于 agent-core-v2)。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
MCP 工具 disclosure 默认值解析 仅 per-server deferred 决定,未配置 = inline 未配置时取 [mcp] default_deferred(缺省 false),在 server (re)connect 时解析并固化 未设置该新键的全部用户:缺省解析 config.deferred ?? false 与旧的 config.deferred === true 逐值等价(true/false/undefined 三态一致),行为不变 不需要——新键缺省即旧行为
运行中修改 [mcp] default_deferred (新键,无旧行为) 不改动既有会话的工具形态;server 重连或进程重启后应用(与 timeout 系配置生效时机一致) 无 reconnect / restart
needs-auth OAuth 合成工具的 disclosure 读原始配置 configOf(name)?.deferred === true 读 entry 上连接时捕获的 deferredOf,与 connected 路径一致 开启 tool-select 且设置 default_deferred 的用户:两种状态下 disclosure 不再可能分歧 不需要
McpConnectionView.configOf 移除 视图暴露原始 server 配置 视图只暴露捕获结果 deferredOf 进程内唯一调用者(needs-auth 路径)已迁移;kap-server / node-sdk / klient 无引用(三包 typecheck 佐证) 无(进程内接口,非 wire 面)
McpDefaultTimeouts / resolveDefaultTimeouts 更名 旧名 McpDefaults / resolveDefaults agent-core-v2 内 4 个构造点已全部迁移;无仓外引用 无(内部接口)
文档句子:deferred 字段「Defaults to false」 表述为固定默认 false 表述为缺省取全局 default_deferred(未设置则为 false),并注明连接时固化 阅读 en/zh MCP 文档的用户;描述对象行为未变(未设新键时语义相同) 不需要

受影响模块与测试覆盖:

  • mcpCore/connection-manager(连接时捕获 + deferredOf):test/mcpCore/connection-manager.test.ts 扩展现有用例,覆盖全局默认生效、deferred: false opt-out、deferredOf,以及「连接后改默认值不影响已注册视图、reconnect 后应用」的固化语义;
  • agent/mcp(注册 disclosure):test/agent/mcp/mcp.test.ts 现有 deferred / needs-auth 用例(FakeMcpManager 同步为 deferredOf);
  • workspaceMcpConfig(tunables 透出):test/workspace/workspaceMcpConfig/workspaceMcpConfig.test.ts 扩展现有用例;
  • 旧行为钉住:未设新键时的等价性由上述全部既有用例 + 远程全量回归保证(m0-dev corepack pnpm test:886 文件 / 16977 用例全过,零失败)。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 531fe37

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T09:12:38.909922Z 531fe37 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@531fe37
npx https://pkg.pr.new/@moonshot-ai/kimi-code@531fe37

commit: 531fe37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 567847a318

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

deferredOf(name: string): boolean {
const entry = this.entries.get(name);
if (entry === undefined) return false;
return entry.config.deferred ?? this.options.resolveDefaults?.().defaultDeferred ?? false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Re-register tools when default_deferred reloads

In an already-open session, changing [mcp].default_deferred through the watched config.toml or /reload updates this resolver but not the disclosure stored in AgentMcpService's existing tool-registry entries. That service only reads resolved().deferred while handling an MCP status event, and no configuration-change event triggers re-registration, so connected servers silently retain the old inline/deferred behavior until they reconnect or the process restarts. Please propagate this setting change to active registrations or explicitly make the setting restart-only instead of resolving it live.

AGENTS.md reference: AGENTS.md:L117-L119

Useful? React with 👍 / 👎.

@sailist
sailist merged commit f28c51c into main Oct 14, 2026
26 of 27 checks passed
@sailist
sailist deleted the feat-289-10-14-mcp-default-deferred branch October 14, 2026 09:19
@github-actions github-actions Bot mentioned this pull request Oct 14, 2026
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Oct 22, 2026
…ure (MoonshotAI#4210)

Ported from MoonshotAI/kimi-code 2.3.0 (f28c51c).

Adaptation: kept this fork's one-line `resolved(name: string):` signature in the
MCP connection view while replacing `configOf` with upstream's `deferredOf`, and
dropped the `McpServerConfig` import that change left unused.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants