Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ public async ValueTask<CallToolResult> CallToolHandler(RequestContext<CallToolRe

activity?.AddTag(TagName.ToolName, request.Params.Name);

// Assume that this is a BaseCommand<T>. 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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ public override async ValueTask<CallToolResult> CallToolHandler(RequestContext<C

if (learn && string.IsNullOrEmpty(command))
{
activity?.SetTag(TagName.IsServerCommandInvoked, false);

return await InvokeToolLearn(request, intent ?? "", tool, cancellationToken);
}
else if (!string.IsNullOrEmpty(tool) && !string.IsNullOrEmpty(command))
Expand Down Expand Up @@ -271,6 +269,7 @@ private async Task<CallToolResult> InvokeChildToolAsync(
};
}

Activity.Current?.SetTag(TagName.IsServerCommandInvoked, true);
Comment thread
alzimmermsft marked this conversation as resolved.
IReadOnlyDictionary<string, IBaseCommand> namespaceCommands;
try
{
Expand Down Expand Up @@ -466,6 +465,7 @@ There was an error finding or calling tool and command.

private async Task<CallToolResult> InvokeToolLearn(RequestContext<CallToolRequestParams> request, string? intent, string namespaceName, CancellationToken cancellationToken)
{
Activity.Current?.SetTag(TagName.IsServerCommandInvoked, false);
var toolsJson = GetChildToolListJson(request, namespaceName);

var learnResponse = new CallToolResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -139,8 +140,6 @@ public override async ValueTask<CallToolResult> CallToolHandler(RequestContext<C
{
if (learn && string.IsNullOrEmpty(command))
{
Activity.Current?.SetTag(TelemetryConstants.TagName.IsServerCommandInvoked, false);

return await InvokeToolLearn(request, intent ?? "", tool, cancellationToken);
}
else if (!string.IsNullOrEmpty(tool) && !string.IsNullOrEmpty(command))
Expand Down Expand Up @@ -244,6 +243,7 @@ private async Task<CallToolResult> InvokeChildToolAsync(RequestContext<CallToolR
}

// At this point we should always have a valid command (child tool) call to invoke.
Activity.Current?.SetTag(TagName.IsServerCommandInvoked, true);
Comment thread
alzimmermsft marked this conversation as resolved.
await NotifyProgressAsync(request, $"Calling {tool} {command}...", cancellationToken);
var toolCallResponse = await client.CallToolAsync(command, parameters, cancellationToken: cancellationToken);
if (toolCallResponse.IsError is true)
Expand Down Expand Up @@ -319,6 +319,7 @@ There was an error finding or calling tool and command.

private async Task<CallToolResult> InvokeToolLearn(RequestContext<CallToolRequestParams> request, string? intent, string tool, CancellationToken cancellationToken)
{
Activity.Current?.SetTag(TagName.IsServerCommandInvoked, false);
var toolsJson = await GetChildToolListJsonAsync(request, tool);

var learnResponse = new CallToolResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -132,8 +133,6 @@ public override async ValueTask<CallToolResult> CallToolHandler(RequestContext<C
learn = true;
}

Activity.Current?.SetTag(TelemetryConstants.TagName.IsServerCommandInvoked, !learn);

if (learn && string.IsNullOrEmpty(tool) && string.IsNullOrEmpty(command))
{
return await RootLearnModeAsync(request, intent ?? "", cancellationToken);
Expand Down Expand Up @@ -206,6 +205,7 @@ private async Task<string> GetToolListJsonAsync(RequestContext<CallToolRequestPa

private async Task<CallToolResult> RootLearnModeAsync(RequestContext<CallToolRequestParams> request, string intent, CancellationToken cancellationToken)
{
Activity.Current?.SetTag(TagName.IsServerCommandInvoked, false);
Comment thread
alzimmermsft marked this conversation as resolved.
var toolsJson = await GetRootToolsJsonAsync();
var learnResponse = new CallToolResult
{
Expand Down Expand Up @@ -236,6 +236,7 @@ Here are the available list of tools.

private async Task<CallToolResult> ToolLearnModeAsync(RequestContext<CallToolRequestParams> request, string intent, string tool, CancellationToken cancellationToken)
{
Activity.Current?.SetTag(TagName.IsServerCommandInvoked, false);
var toolsJson = await GetToolListJsonAsync(request, tool);
if (string.IsNullOrEmpty(toolsJson))
{
Expand Down Expand Up @@ -272,6 +273,7 @@ private async Task<CallToolResult> ToolLearnModeAsync(RequestContext<CallToolReq

private async Task<CallToolResult> CommandModeAsync(RequestContext<CallToolRequestParams> request, string intent, string tool, string command, Dictionary<string, object?> parameters, CancellationToken cancellationToken)
{
Activity.Current?.SetTag(TagName.IsServerCommandInvoked, true);
McpClient? client;

try
Expand Down
2 changes: 1 addition & 1 deletion core/Azure.Mcp.Core/src/Commands/CommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 4 additions & 6 deletions core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,10 +40,10 @@ public TelemetryService(IMachineInformationProvider informationProvider,
ILogger<TelemetryService> logger)
{
_isEnabled = options.Value.IsTelemetryEnabled;
_tagsList = new List<KeyValuePair<string, object?>>()
{
_tagsList =
[
new(TagName.AzureMcpVersion, options.Value.Version),
};
];

if (serverOptions?.Value != null)
{
Expand All @@ -68,7 +66,7 @@ public TelemetryService(IMachineInformationProvider informationProvider,
}

CheckInitialization();
return _tagsList.ToImmutableList();
return [.. _tagsList];
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions servers/Azure.Mcp.Server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down