kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

MCP tools/list_changed notifications do not refresh session-visible tool registry

Open starSumi opened this issue 5 months ago • 1 comments

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:

  1. Start a stdio MCP server that advertises capabilities.tools.listChanged: true.
  2. Initial tools/list returns one tool: enable_extra_tool.
  3. Call enable_extra_tool.
  4. The server returns the tools/call response, then sends notifications/tools/list_changed.
  5. A subsequent tools/list returns enable_extra_tool and dynamic_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.ts
  • packages/agent-core/src/mcp/client-stdio.ts
  • packages/agent-core/src/mcp/client-http.ts
  • packages/agent-core/src/mcp/client-sse.ts
  • packages/agent-core/src/mcp/connection-manager.ts
  • packages/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.ts passed: 30 tests.
  • pnpm --filter @moonshot-ai/agent-core run typecheck passed.
  • A local lazy MCP proxy end-to-end passed: after calling mcp_load_server_fake-lazy-server-1, Kimi received notifications/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.tools and entry.enabledNames;
  • emit the existing status update path.

starSumi avatar Jun 26 '26 11:06 starSumi

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.

glmn avatar Oct 07 '26 19:10 glmn