Always set IsServerCommandInvoked to false when first entering CallToolHandler#1718
Merged
alzimmermsft merged 5 commits intomicrosoft:mainfrom Feb 13, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR standardizes how tool loaders set the TagName.IsServerCommandInvoked activity tag so telemetry reliably distinguishes “learning/listing/routing” from actual server command/tool execution across the MCP server tool-loading pipeline.
Changes:
- Set
IsServerCommandInvoked=falseimmediately upon entering eachCallToolHandler, and set it totrueright before executing a command (IBaseCommand.ExecuteAsync) or proxying a tool call (McpClient.CallToolAsync). - Ensure learn-mode flows explicitly reset
IsServerCommandInvoked=falseto avoid leaking a priortruevalue after error-driven routing into learning paths. - Minor modernizations/cleanup (collection expressions, simplified type references).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ToolLoading/SingleProxyToolLoader.cs | Applies the new IsServerCommandInvoked tagging rules across root learn/tool learn/command execution paths; minor initialization and doc cleanup. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ToolLoading/ServerToolLoader.cs | Applies consistent tag initialization and flips to true only for actual proxied tool execution; uses collection expressions. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ToolLoading/RegistryToolLoader.cs | Initializes tag to false on entry and sets true immediately before proxying the registry-discovered tool call; minor collection expression cleanup. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs | Removes premature true tagging and sets true only when executing the underlying command; resets to false when entering learn paths; collection expression cleanup. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ToolLoading/CompositeToolLoader.cs | Ensures composite routing starts with IsServerCommandInvoked=false before delegating to the selected child loader. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ToolLoading/CommandFactoryToolLoader.cs | Ensures tag is false on entry and flips to true immediately before ExecuteAsync; simplifies activity tagging flow. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ToolLoading/BaseToolLoader.cs | Minor type qualification cleanup for elicitation request creation. |
conniey
reviewed
Feb 13, 2026
conniey
reviewed
Feb 13, 2026
conniey
reviewed
Feb 13, 2026
conniey
approved these changes
Feb 13, 2026
20 tasks
colbytimm
pushed a commit
to colbytimm/microsoft-mcp
that referenced
this pull request
Apr 20, 2026
…olHandler (microsoft#1718) * Always set IsServerCommandInvoked to false when first entering CallToolHandler * Changelog and some tests * Fix small compilation issue * Cleanup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes cases where
IsServerCommandInvokedwasn't being set in some cases. At a high-level the changes are as follows (and all futureIToolLoader/BaseToolLoaderimplementations should follow this):CallToolHandleris invokedIsServerCommandInvokedshould get set tofalseright away.IBaseCommand.ExecuteAsyncorMcpClient.CallToolAsyncare about to be calledIsServerCommandInvokedshould get set totrue.IToolHandler/BaseToolLoaderhas learning paths, when those are invokedIsServerCommandInvokedshould get set tofalseno matter what. This handles potential cases where anIsServerCommandInvoked=truecases calls into learning if there was an error.GitHub issue number?
[Link to the GitHub issue this PR addresses]Pre-merge Checklist
servers/Azure.Mcp.Server/CHANGELOG.mdand/orservers/Fabric.Mcp.Server/CHANGELOG.mdfor product changes (features, bug fixes, UI/UX, updated dependencies)servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationeng/scripts/Process-PackageReadMe.ps1. See Package README/servers/Azure.Mcp.Server/docs/azmcp-commands.mdand/or/docs/fabric-commands.md.\eng\scripts\Update-AzCommandsMetadata.ps1to update tool metadata in azmcp-commands.md (required for CI)ToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.json/servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline