MCP tools/list_changed notifications do not refresh session-visible tool registry
MCP tools/list_changed notifications do not refresh session-visible tool registry
Summary
Kimi Code connects to MCP servers and discovers tools on connect/reconnect, but the active session tool registry does not refresh when a connected MCP server sends notifications/tools/list_changed.
This blocks same-session dynamic MCP workflows, including lazy MCP servers that initially expose a loader tool and then expose real downstream tools after the loader is called.
Reproduction
Local repro used a stdio MCP fixture and McpConnectionManager directly, without a model account or TUI:
- Start a stdio MCP server that advertises
capabilities.tools.listChanged: true. - Initial
tools/listreturns one tool:enable_extra_tool. - Call
enable_extra_tool. - The server returns the
tools/callresponse, then sendsnotifications/tools/list_changed. - A subsequent
tools/listreturnsenable_extra_toolanddynamic_echo.
Before the local patch, the underlying client could re-list the server tools, but McpConnectionManager continued exposing only the old session-visible tools.
Expected
When a connected server advertises tools.listChanged and sends notifications/tools/list_changed, Kimi should refresh that server's tools and emit the existing MCP status update path so the active session sees the new registry.
Actual
Kimi discovers tools during connect/reconnect, but does not route MCP SDK listChanged.tools.onChanged results back into McpConnectionManager.
Source Locus
packages/agent-core/src/mcp/client-shared.tspackages/agent-core/src/mcp/client-stdio.tspackages/agent-core/src/mcp/client-http.tspackages/agent-core/src/mcp/client-sse.tspackages/agent-core/src/mcp/connection-manager.tspackages/agent-core/test/mcp/connection-manager.test.ts
The installed MCP SDK already supports ClientOptions.listChanged.tools.onChanged in @modelcontextprotocol/[email protected].
Related
#965: schema-size pressure from many MCP tools; lazy loading is one mitigation path.#218: plugin reload hot-apply, related to MCP server lifecycle but not server-side dynamic tool list notifications.#383: reload commands, useful manual workaround but not same-session protocol notification handling.#286: MCP list display behavior, not the same refresh issue.
Local Validation Of Proposed Fix
Validated locally on branch fix/mcp-tool-list-changed-refresh, commit f2fd6249:
pnpm --filter @moonshot-ai/agent-core exec vitest run test/mcp/connection-manager.test.tspassed: 30 tests.pnpm --filter @moonshot-ai/agent-core run typecheckpassed.- A local lazy MCP proxy end-to-end passed: after calling
mcp_load_server_fake-lazy-server-1, Kimi receivednotifications/tools/list_changed, re-listed tools, and removed the loaded server's loader tool from manager state.
Proposed Fix Direction
Wire MCP SDK listChanged.tools.onChanged into the existing MCP client wrappers, then update McpConnectionManager only for the current connected attempt:
- ignore stale reconnect attempts;
- log refresh errors without dropping the existing tool registry;
- validate refreshed input schemas through the same path as startup discovery;
- update
entry.toolsandentry.enabledNames; - emit the existing status update path.
Still the case on Kimi Code 2.1.1 and main at 21406fb. Note that the open PR #1350 changes only packages/agent-core (v1). The v2 engine the CLI runs now has its own clients in packages/agent-core-v2/src/mcpCore/client-{http,sse,stdio}.ts, and none of them sets a listChanged option or handles the notification. A fix for this issue would need to cover v2 as well.
Our use case: we run Kimi Code in a desktop app (NeuroSquad) whose MCP server grants tools when the user connects the agent to a new resource mid-session, and sends tools/list_changed. For Kimi we list every capability up front and refuse ungranted ones at call time, and third-party servers connected mid-session only reach new sessions.