Skip to content

Comments

kusto_query: migrate query path/parsing to v2 and add --show-stats#1787

Open
gholliday wants to merge 2 commits intomicrosoft:mainfrom
gholliday:granth/kusto-query-v2-show-stats
Open

kusto_query: migrate query path/parsing to v2 and add --show-stats#1787
gholliday wants to merge 2 commits intomicrosoft:mainfrom
gholliday:granth/kusto-query-v2-show-stats

Conversation

@gholliday
Copy link
Member

What does this PR do?

This PR updates the existing kusto_query tool to use Kusto query v2 response handling and adds an optional --show-stats parameter so users can retrieve execution statistics (CPU, memory, cache, extents, network, and cross-cluster breakdown) alongside query results.

It also updates tests and docs for the new behavior, keeps /v1/rest/mgmt unchanged, and adds a changelog entry.

GitHub issue number?

Closes #1786

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Updated changelog entry under servers/Azure.Mcp.Server/changelog-entries/
  • For MCP tool changes:
    • One tool per PR: This PR modifies only kusto_query
    • Updated servers/Azure.Mcp.Server/README.md documentation
    • Validate README.md changes using eng/scripts/Process-PackageReadMe.ps1 (not applicable - README not changed)
    • Updated command list in /servers/Azure.Mcp.Server/docs/azmcp-commands.md
    • Ran ./eng/scripts/Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md
    • For modified tool descriptions, ran ToolDescriptionEvaluator with score >= 0.4 and top-3 ranking for related prompts
    • For tools with new names, update consolidated-tools.json (not applicable - no new tool name)
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /servers/Azure.Mcp.Server/docs/e2eTestPrompts.md

Validation run

  • dotnet build .\mcp.sln
  • ./eng/scripts/Test-Code.ps1 -Paths Kusto
  • MCP smoke test over stdio protocol (initialize + tools/list + kusto_query) against https://help.kusto.windows.net with and without show-stats

Invoking Livetests

Copilot submitted PRs are not trustworthy by default. Users with write access to the repo need to validate the contents of this PR before leaving a comment with the text /azp run mcp - pullrequest - live. This will trigger the necessary livetest workflows to complete required validation.

Migrate query requests to /v2/rest/query with required headers and decompression, parse v2 frames including DataSetCompletion errors, and add --show-stats structured statistics output with unit tests, docs, and changelog entry.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link

Thank you for your contribution @gholliday! We will review the pull request and get back to you soon.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the kusto_query tool to execute queries via Kusto’s /v2/rest/query frame-based response format and adds an optional --show-stats flag to return structured execution statistics alongside results.

Changes:

  • Migrates Kusto query execution to /v2/rest/query and adds v2 frame parsing (PrimaryResult + DataSetCompletion error handling).
  • Adds --show-stats option and plumbs statistics extraction from QueryCompletionInformation frames through to the command response.
  • Adds/updates unit tests and updates command documentation and changelog entry.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.Kusto/src/Services/KustoService.cs Adds v2 frame parsing, statistics extraction, and new QueryItemsWithStatisticsAsync APIs.
tools/Azure.Mcp.Tools.Kusto/src/Services/KustoClient.cs Switches query endpoint to /v2/rest/query, uses named HttpClient, and adds readonly/compression/connection headers.
tools/Azure.Mcp.Tools.Kusto/src/Services/IKustoService.cs Extends interface with new tuple-returning QueryItemsWithStatisticsAsync overloads.
tools/Azure.Mcp.Tools.Kusto/src/Commands/QueryCommand.cs Adds --show-stats option and includes optional statistics in the response model.
tools/Azure.Mcp.Tools.Kusto/src/Options/QueryOptions.cs Adds ShowStats option binding model property.
tools/Azure.Mcp.Tools.Kusto/src/Options/KustoOptionDefinitions.cs Defines --show-stats option.
tools/Azure.Mcp.Tools.Kusto/src/KustoSetup.cs Registers a named HttpClient configured for gzip/deflate decompression.
tools/Azure.Mcp.Tools.Kusto/tests/Azure.Mcp.Tools.Kusto.UnitTests/QueryCommandTests.cs Updates tests to use new service API and adds coverage for --show-stats.
tools/Azure.Mcp.Tools.Kusto/tests/Azure.Mcp.Tools.Kusto.UnitTests/KustoServiceTests.cs Adds new tests for v2 frame parsing, error handling, and statistics extraction.
tools/Azure.Mcp.Tools.Kusto/tests/Azure.Mcp.Tools.Kusto.UnitTests/KustoClientTests.cs Adds assertions for v2 endpoint usage and expected request headers.
servers/Azure.Mcp.Server/docs/e2eTestPrompts.md Adds an e2e prompt that exercises statistics output.
servers/Azure.Mcp.Server/docs/azmcp-commands.md Documents optional [--show-stats] on kusto query.
servers/Azure.Mcp.Server/changelog-entries/copilot-kusto-query-v2-show-stats.yaml Changelog entry for v2 migration and the new stats option.

Remove duplicate QueryItems validation, replace brittle columns JSON string construction with writer-based object creation, and avoid reparsing rows by cloning JsonElement directly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@gholliday
Copy link
Member Author

I can't get the tests working, and it appears that they are a pre-existing issue. I've contributed this to microsoft/fabric-rti-mcp#123 instead, so feel free to close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

[BUG] kusto_query does not expose query execution stats for users

3 participants