Skip to content

mcp: recreate the toolset when server instructions change#278141

Merged
connor4312 merged 1 commit intomainfrom
connor4312/277894
Nov 18, 2025
Merged

mcp: recreate the toolset when server instructions change#278141
connor4312 merged 1 commit intomainfrom
connor4312/277894

Conversation

@connor4312
Copy link
Member

Closes #277894

Copilot AI review requested due to automatic review settings November 18, 2025 16:20
@connor4312 connor4312 enabled auto-merge (squash) November 18, 2025 16:20
@connor4312 connor4312 self-assigned this Nov 18, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses the issue where toolsets are not recreated when MCP server instructions or metadata change. The changes track server metadata as part of the tool source data and compare it on each autorun iteration to detect when recreation is needed.

Key Changes:

  • Modified mcpServerToSourceData to accept an optional IReader parameter and use .read(reader) instead of .get() to enable dependency tracking on server metadata
  • Updated the autorun logic in McpLanguageModelToolContribution to compare previous and current source data (including server instructions) and recreate the toolset when changes are detected
  • Changed the storage structure from DisposableStore to a custom Rec type that includes both the source data and disposal capability

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/vs/workbench/contrib/mcp/common/mcpTypesUtils.ts Added optional IReader parameter to mcpServerToSourceData to enable observable dependency tracking on server metadata
src/vs/workbench/contrib/mcp/common/mcpLanguageModelToolContribution.ts Implemented source data comparison logic to detect metadata changes and trigger toolset recreation, with a new Rec type to store source alongside dispose function

Comment on lines 59 to +61
toDelete.delete(server);
continue;
if (!previousRec.source || equals(previousRec.source, mcpServerToSourceData(server, reader))) {
continue; // same definition, no need to update
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The condition !previousRec.source will be true if the server has no tools yet and the Lazy hasn't been evaluated. In this case, if server metadata (instructions or serverName) changes before any tools are registered, the toolset won't be recreated because the check will pass and continue on line 61.

Consider eagerly setting rec.source immediately after creating the record, before the Lazy:

const store = new DisposableStore();
const rec: Rec = { source: mcpServerToSourceData(server), dispose: () => store.dispose() };
const toolSet = new Lazy(() => {
    const toolSet = store.add(this._toolsService.createToolSet(
        rec.source!,
        server.definition.id, server.definition.label,
        {
            icon: Codicon.mcp,
            description: localize('mcp.toolset', "{0}: All Tools", server.definition.label)
        }
    ));
    return { toolSet, source: rec.source! };
});

Copilot uses AI. Check for mistakes.
@connor4312 connor4312 merged commit 90fcf63 into main Nov 18, 2025
28 checks passed
@connor4312 connor4312 deleted the connor4312/277894 branch November 18, 2025 16:45
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Jan 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP server instructions are not updated

3 participants