Skip to content

fix: refresh tool and prompt caches after remote MCP server reconnect#2246

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/fix-docker-agent-issue-2244-mcp-e2e-test-c1254c45
Mar 25, 2026
Merged

fix: refresh tool and prompt caches after remote MCP server reconnect#2246
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/fix-docker-agent-issue-2244-mcp-e2e-test-c1254c45

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 25, 2026

After a remote MCP server restarts, the tool/prompt caches were invalidated but the runtime was never notified to re-fetch. This caused stale tools to be returned after reconnection.

Changes

  • pkg/tools/mcp/mcp.go: Call refreshToolCache and refreshPromptCache in watchConnection after a successful restart so the runtime picks up the new server's tools/prompts.
  • pkg/tools/mcp/reconnect_test.go: Add TestRemoteReconnectRefreshesTools which verifies that after a server restarts with different tools, Tools() returns the new set and toolsChangedHandler is called. Extract startMCPServer/allocateAddr helpers to reduce duplication.

Fixes #2244

After a successful reconnect in watchConnection, eagerly call
refreshToolCache so the runtime picks up the new server's tools and
the toolsChangedHandler is invoked. Without this, the runtime kept
using its stale copy of the tool list.

Add TestRemoteReconnectRefreshesTools to verify that when a remote
MCP server restarts with a different set of tools the Toolset
returns the updated tools and notifies the handler.

Extract startMCPServer and allocateAddr test helpers to reduce
duplication across reconnect tests.

Fixes docker#2244

Assisted-By: docker-agent
@dgageot dgageot requested a review from a team as a code owner March 25, 2026 17:12
@dgageot dgageot merged commit 338f317 into docker:main Mar 25, 2026
8 checks passed
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.

Remove MCP has old tools after a restart

3 participants