Skip to content

Telemetry: emit per-tool identifier via CosmosClient ApplicationName so DailyUserAgentSummary can break down by tool #145

Description

@sajeetharan

Telemetry: emit per-tool identifier via CosmosClient ApplicationName

Problem

DailyUserAgentSummary.UserAgent is the only field our downstream dashboards can bucket by, and today it cannot break down MCP Toolkit calls by tool. Every one of the 8 [McpServerTool] methods in [McpServerToolType] CosmosDbTools (in src/AzureCosmosDB.MCP.Toolkit/Program.cs) constructs its CosmosClient with the same hardcoded value:

using var client = new CosmosClient(endpoint, credential, new CosmosClientOptions
{
    ApplicationName = "AzureCosmosDBMCP"
});

The tool name currently only lives in ILogger messages (e.g. "Listing databases from Cosmos DB", "Received MCP tool call: {ToolName}"). Those logs flow to stdout / Container Apps / App Insights — not into the Cosmos SDK UserAgent that surfaces in DailyUserAgentSummary.UserAgent. So the per-tool signal simply isn't in the telemetry the dashboard reads.

Fix

Encode the tool name into ApplicationName using the format:

AzureCosmosDBMCP-<kebab-tool-name>

Separator - (dash) avoids collision with / and , which the Cosmos SDK already uses in its own UA segments, giving an unambiguous regex.

Mapping

Method ApplicationName
ListDatabases AzureCosmosDBMCP-list-databases
ListCollections AzureCosmosDBMCP-list-collections
GetRecentDocuments AzureCosmosDBMCP-get-recent-documents
TextSearch AzureCosmosDBMCP-text-search
FindDocumentByID AzureCosmosDBMCP-find-document-by-id
GetApproximateSchema AzureCosmosDBMCP-get-approximate-schema
VectorSearch AzureCosmosDBMCP-vector-search
HybridSearch AzureCosmosDBMCP-hybrid-search

KQL (dashboard tile)

DailyUserAgentSummary
| where UserAgent has "AzureCosmosDBMCP-"
| extend Tool = extract(@"AzureCosmosDBMCP-([a-z][a-z0-9-]*)", 1, UserAgent)
| where isnotempty(Tool)
| summarize Requests = sum(Count) by Tool, bin(Date, 1d)
| render columnchart

Scope

  • Change 8 ApplicationName string literals in src/AzureCosmosDB.MCP.Toolkit/Program.cs.
  • Add a short comment near the first modified site documenting the convention for future [McpServerTool] additions.
  • Not changing the singleton CosmosClient built in CosmosClientFactory.BuildClientOptions — it feeds CosmosDbToolsService, which is not on the MCP tool path today, and a singleton fundamentally cannot carry a per-tool suffix. Documented as a known limitation.

Spec

Full spec: docs/specs/tool-name-in-useragent.md

Acceptance criteria

  • Each of the 8 [McpServerTool] methods emits a distinct ApplicationName matching the table above.
  • Build passes (dotnet build).
  • Comment near the first modified site documents the convention.
  • Spec file docs/specs/tool-name-in-useragent.md merged alongside code change.
  • Dashboard tile using the KQL above successfully bins requests by tool after next deployment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions