diff --git a/core/Azure.Mcp.Core/src/Areas/Server/Commands/Runtime/McpRuntime.cs b/core/Azure.Mcp.Core/src/Areas/Server/Commands/Runtime/McpRuntime.cs index 0b614d38a3..7000cd1469 100644 --- a/core/Azure.Mcp.Core/src/Areas/Server/Commands/Runtime/McpRuntime.cs +++ b/core/Azure.Mcp.Core/src/Areas/Server/Commands/Runtime/McpRuntime.cs @@ -77,10 +77,6 @@ public async ValueTask CallToolHandler(RequestContext. If not, the tag will be updated in - // the children ToolLoaders. - activity?.AddTag(TagName.IsServerCommandInvoked, true); - var symbol = OptionDefinitions.Common.Subscription; var subscriptionArgument = request.Params?.Arguments? diff --git a/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs b/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs index 65ba937193..f377f23569 100644 --- a/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs +++ b/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs @@ -173,8 +173,6 @@ public override async ValueTask CallToolHandler(RequestContext InvokeChildToolAsync( }; } + Activity.Current?.SetTag(TagName.IsServerCommandInvoked, true); IReadOnlyDictionary namespaceCommands; try { @@ -466,6 +465,7 @@ There was an error finding or calling tool and command. private async Task InvokeToolLearn(RequestContext request, string? intent, string namespaceName, CancellationToken cancellationToken) { + Activity.Current?.SetTag(TagName.IsServerCommandInvoked, false); var toolsJson = GetChildToolListJson(request, namespaceName); var learnResponse = new CallToolResult diff --git a/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/ServerToolLoader.cs b/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/ServerToolLoader.cs index bc41832413..4eabe7940b 100644 --- a/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/ServerToolLoader.cs +++ b/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/ServerToolLoader.cs @@ -9,6 +9,7 @@ using ModelContextProtocol; using ModelContextProtocol.Client; using ModelContextProtocol.Protocol; +using static Azure.Mcp.Core.Services.Telemetry.TelemetryConstants; namespace Azure.Mcp.Core.Areas.Server.Commands.ToolLoading; @@ -139,8 +140,6 @@ public override async ValueTask CallToolHandler(RequestContext InvokeChildToolAsync(RequestContext InvokeToolLearn(RequestContext request, string? intent, string tool, CancellationToken cancellationToken) { + Activity.Current?.SetTag(TagName.IsServerCommandInvoked, false); var toolsJson = await GetChildToolListJsonAsync(request, tool); var learnResponse = new CallToolResult diff --git a/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/SingleProxyToolLoader.cs b/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/SingleProxyToolLoader.cs index 99400ca9a7..f0b9942df9 100644 --- a/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/SingleProxyToolLoader.cs +++ b/core/Azure.Mcp.Core/src/Areas/Server/Commands/ToolLoading/SingleProxyToolLoader.cs @@ -8,6 +8,7 @@ using ModelContextProtocol; using ModelContextProtocol.Client; using ModelContextProtocol.Protocol; +using static Azure.Mcp.Core.Services.Telemetry.TelemetryConstants; namespace Azure.Mcp.Core.Areas.Server.Commands.ToolLoading; @@ -132,8 +133,6 @@ public override async ValueTask CallToolHandler(RequestContext GetToolListJsonAsync(RequestContext RootLearnModeAsync(RequestContext request, string intent, CancellationToken cancellationToken) { + Activity.Current?.SetTag(TagName.IsServerCommandInvoked, false); var toolsJson = await GetRootToolsJsonAsync(); var learnResponse = new CallToolResult { @@ -236,6 +236,7 @@ Here are the available list of tools. private async Task ToolLearnModeAsync(RequestContext request, string intent, string tool, CancellationToken cancellationToken) { + Activity.Current?.SetTag(TagName.IsServerCommandInvoked, false); var toolsJson = await GetToolListJsonAsync(request, tool); if (string.IsNullOrEmpty(toolsJson)) { @@ -272,6 +273,7 @@ private async Task ToolLearnModeAsync(RequestContext CommandModeAsync(RequestContext request, string intent, string tool, string command, Dictionary parameters, CancellationToken cancellationToken) { + Activity.Current?.SetTag(TagName.IsServerCommandInvoked, true); McpClient? client; try diff --git a/core/Azure.Mcp.Core/src/Commands/CommandFactory.cs b/core/Azure.Mcp.Core/src/Commands/CommandFactory.cs index ab0325b89b..f4c02b92ac 100644 --- a/core/Azure.Mcp.Core/src/Commands/CommandFactory.cs +++ b/core/Azure.Mcp.Core/src/Commands/CommandFactory.cs @@ -175,7 +175,7 @@ private void ConfigureCommands(CommandGroup group) private void ConfigureCommandHandler(Command command, IBaseCommand implementation) { - command.SetAction(async (ParseResult parseResult, CancellationToken ct) => + command.SetAction(async (parseResult, ct) => { _logger.LogTrace("Executing '{Command}'.", command.Name); diff --git a/core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs b/core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs index 1165027ca7..9f67329095 100644 --- a/core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs +++ b/core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using System.Collections.Generic; -using System.Collections.Immutable; using System.Diagnostics; using Azure.Mcp.Core.Areas.Server.Options; using Azure.Mcp.Core.Configuration; @@ -42,10 +40,10 @@ public TelemetryService(IMachineInformationProvider informationProvider, ILogger logger) { _isEnabled = options.Value.IsTelemetryEnabled; - _tagsList = new List>() - { + _tagsList = + [ new(TagName.AzureMcpVersion, options.Value.Version), - }; + ]; if (serverOptions?.Value != null) { @@ -68,7 +66,7 @@ public TelemetryService(IMachineInformationProvider informationProvider, } CheckInitialization(); - return _tagsList.ToImmutableList(); + return [.. _tagsList]; } /// diff --git a/servers/Azure.Mcp.Server/CHANGELOG.md b/servers/Azure.Mcp.Server/CHANGELOG.md index 6a9747b508..4e726db795 100644 --- a/servers/Azure.Mcp.Server/CHANGELOG.md +++ b/servers/Azure.Mcp.Server/CHANGELOG.md @@ -12,6 +12,8 @@ The Azure MCP Server updates automatically by default whenever a new release com ### Other Changes +- Updated how `IsServerCommandInvoked` telemetry is captured to more correctly report whether learning or tool call was performed. [[#874](https://github.com/microsoft/mcp/pull/874)] + ## 0.9.4 (2025-10-17) ### Features Added