Skip to content

Fix ask mode MCP tool availability after server discovery - #334641

Closed
luotianyiismywife wants to merge 1 commit into
microsoft:mainfrom
luotianyiismywife:fix/334569-ask-mode-mcp-tool-availability
Closed

Fix ask mode MCP tool availability after server discovery#334641
luotianyiismywife wants to merge 1 commit into
microsoft:mainfrom
luotianyiismywife:fix/334569-ask-mode-mcp-tool-availability

Conversation

@luotianyiismywife

Copy link
Copy Markdown

Description

Fixes #334569 — MCP tool calls intermittently rejected with "disabled by the user" while the cache shows enabled and the server log shows execution.

Root Cause

In ask mode, MCP tools can only enter availableTools via request.toolReferences (the askAgentToolFilter in askAgentIntent.ts). When the user references an MCP server (via the @ picker), the toolset is expanded into a static snapshot at request-parse time (chatRequestParser.ts):

const value = Array.from(toolset.getTools()).map(t => ...);

MCP servers connect and discover their tools asynchronously (observed ~6s in the issue's reproduction: server start → Discovered 48 tools). If the request is parsed while discovery is still in progress, the snapshot only contains the tools registered up to that point. Tools discovered later are registered in the tools service but never enter availableTools — the model's calls to them are then rejected with the misleading error Tool ... is currently disabled by the user.

Fix

In askAgentIntent.ts, when the user referenced an MCP server (any toolReferences entry starts with the mcp_ prefix used by MCP tool names), include all currently registered MCP tools in the filter. Availability now reflects the live registration state rather than the possibly-stale request snapshot:

export function askAgentToolFilter(tool, request): boolean {
    if (tool.tags.some(tag => lookForTags.has(tag)) || request.toolReferences.some(ref => ref.name === tool.name)) {
        return true;
    }
    if (tool.tags.includes('mcp')) {
        // The user referenced an MCP server; include all currently
        // registered MCP tools so availability reflects the live
        // registration state rather than the possibly-stale snapshot.
        return request.toolReferences.some(ref => ref.name.startsWith('mcp_'));
    }
    return false;
}

Validation

  • Added askAgentIntent.spec.ts with 6 unit tests covering:
    • codesearch-tagged tools still included
    • directly referenced tools still included
    • unreferenced non-MCP tools excluded
    • MCP tools included when an MCP server tool was referenced (snapshot case)
    • MCP tools excluded when only non-MCP tools were referenced
    • MCP tools excluded when no tools were referenced
  • All 6 tests pass (vitest run src/extension/intents/test/node/askAgentIntent.spec.ts).

Related

When the user references an MCP server in ask mode, the toolReferences
in the request are a snapshot taken when the request was parsed. If the
MCP server is still discovering its tools at that point, the snapshot
contains only the tools registered so far, and any tools discovered
later are reported as "disabled by the user" when the model tries to
call them (they are not in availableTools).

Include all currently registered MCP tools in the ask agent tool filter
when the user referenced an MCP server, so availability reflects the
live registration state rather than the possibly-stale snapshot.

Fixes microsoft#334569

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The code fails unused-local checks and exposes tools from unreferenced MCP servers.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes ask-mode MCP availability when discovery completes after request parsing.

Changes:

  • Adds live MCP tool filtering for ask mode.
  • Adds six unit tests for tool inclusion behavior.
File summaries
File Description
askAgentIntent.ts Expands MCP tool availability after discovery.
askAgentIntent.spec.ts Tests ask-mode tool filtering.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread extensions/copilot/src/extension/intents/node/askAgentIntent.ts
Comment thread extensions/copilot/src/extension/intents/node/askAgentIntent.ts
@luotianyiismywife

Copy link
Copy Markdown
Author

This PR is superseded by #334657 📌

Copilot's review confirmed the concern with the mcp_-prefix approach used here: it would make all registered MCP tools available after referencing any single one, widening the authorization boundary to unrelated servers.

The proper fix is implemented in #334657 (Scope MCP tool availability to referenced servers only), which:

  • Resolves the referenced tool's LanguageModelToolMCPSource to identify the server
  • Only includes newly discovered tools from that same server
  • Excludes tools from distinct servers (with a dedicated test)

I'll leave this PR open for reference, but #334657 is the recommended one to merge. Happy to close this if preferred.

@luotianyiismywife

Copy link
Copy Markdown
Author

Closing in favor of #334657 (server-scoped fix). As Copilot's review noted, the mcp_ prefix approach in this PR widened the availability scope to all configured MCP servers after referencing just one - the fix in #334657 preserves the per-server authorization boundary while still solving the snapshot timing issue. Thanks Copilot for catching that!

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.

MCP tool calls intermittently rejected "disabled by the user" while cache shows enabled and server log shows execution

3 participants