Skip to content

Update optimization tools - #3899

Merged
sanjaytholanim merged 7 commits into
mainfrom
smanojkumar/update-optimization-tools
Oct 13, 2026
Merged

sanjaytholanim merged 7 commits into
mainfrom
smanojkumar/update-optimization-tools

Conversation

@sanjaytholanim

@sanjaytholanim sanjaytholanim commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Updates the Azure MCP Optimization toolset (optimization recommendation list, explain, alternatives):

  • optimization recommendation list – subscription is now optional. The command now derives from AuthenticatedCommand instead of SubscriptionCommand. When --subscription is omitted, the query covers all accessible subscriptions in the signed-in session's default tenant, or in the --tenant tenant (ID or display name) when one is given. The tool never asks for a tenant. Unknown tenant or subscription names now return 404 instead of 500.
  • Tenant-correct Resource Graph queries (bug fix). ARG queries now use an ArmClient created for the target tenant. Previously a TenantResource was picked from the default client, so the token always came from the default tenant and tenant display names were ignored.
  • Unattached-disk recommendations are summarized. The main cost query excludes the "Review disks that are not attached to a VM" recommendation type (48eda464-1485-4dcf-a674-d0905df5054a). A new UnattachedDiskSummaryQuery runs in parallel and returns one diskRecommendationSummary with a count, the affected subscription IDs, and a portal actionUrl. It applies the same tracked, suppression, and subscription/resource-group exclusion filters as the main list, through shared KQL subqueries. If the summary query fails, the error is logged and the main list is still returned.
  • Savings fallback. When extendedProperties has no savings amounts, monthly/annual savings and currency now come from properties.savings.retail.dailyPotentialSavings / providerCurrency.
  • Output. impact is still projected for every recommendation. The explain query projects id, resourceGroup, subscriptionId, and properties with impact removed.
  • Tool descriptions. List, explain, and alternatives now call results "cost optimization recommendations" and tell the agent not to mention "Azure Advisor". The list description also covers the optional subscription and how to show the disk summary.
  • Docs and tests. Updated azmcp-commands.md, added an e2e prompt for the all-subscriptions case, added a changelog entry, and added unit tests (DiskRecommendationSummaryTests, updated RecommendationListCommandTests).

GitHub issue number?

[Link to the GitHub issue this PR addresses]

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
    • Created a changelog entry if the change falls among the following: new feature, bug fix, UI/UX update, breaking change, or updated dependencies. Follow the changelog entry guide
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes running the script ./eng/scripts/Process-PackageReadMe.ps1. See Package README
    • For new or modified tool descriptions (excluding Fabric MCP tools), ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json — N/A, no new or renamed tools
    • For renamed tools, follow the Tool Rename Checklist and tag the PR with the breaking-change label — N/A, no renamed tools
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description — N/A, no new tools
  • Extra steps for Azure MCP Server tool changes:
    • 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 (required for CI)
    • Updated test prompts in servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

Validation

Command Result
dotnet test in Azure.Mcp.Tools.Optimization.Tests with TestMode: Playback (unit + recorded) ✅ Passed — 45/45
azmcp optimization recommendation list --top 5 (no --subscription/--tenant, live) ✅ 200 — used the signed-in default tenant; 5 recommendations across 3 subscriptions with impact; disk summary of 25 disks in 4 subscriptions
dotnet test --filter-class "*OptimizationCommandTests" with TestMode: Record against the test subscription ✅ Passed — 4/4; recordings pushed as Azure.Mcp.Tools.Optimization.Tests_b02258d127 (assets.json updated)
Resource Graph REST: old vs new unattached-disk summary query across the default tenant ✅ Both return 25 disks in 4 subscriptions; the new joins don't drop or duplicate rows
dotnet build servers/Azure.Mcp.Server/src ✅ Succeeded — 0 warnings, 0 errors
dotnet format tools/Azure.Mcp.Tools.Optimization/src and .../tests/... with --verify-no-changes ✅ Clean
./eng/scripts/Update-AzCommandsMetadata.ps1 ✅ No metadata drift
.\eng\common\spelling\Invoke-Cspell.ps1 -FileList <changed files> ✅ 0 issues
ToolDescriptionEvaluator ⚠️ Not run — no AOAI_ENDPOINT / TEXT_EMBEDDING_API_KEY available locally; the CI step also skips without them

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Query correctness, tenant scoping, recorded-test assets, and required evaluator evidence remain unresolved.

6 open findings
What changed in this PR

Updates optimization recommendation tools to support subscriptionless queries, summarize unattached disks, and revise recommendation terminology.

Changes:

  • Makes --subscription optional for recommendation listing.
  • Adds unattached-disk summaries and retail-savings fallback logic.
  • Updates tool descriptions, tests, documentation, and changelog.
File Description
DiskRecommendationSummaryTests.cs Tests disk summary generation and queries.
RecommendationListCommandTests.cs Tests optional subscription and summary output.
OptimizationStrings.cs Adds optional-subscription guidance.
OptimizationService.cs Adds unscoped queries and disk summaries.
OptimizationKqlQueries.cs Updates recommendation queries and projections.
IOptimizationService.cs Makes subscription nullable.
RecommendationListOptions.cs Uses optional-subscription description.
RecommendationExplainOptions.cs Revises resource ID guidance.
RecommendationAlternativesOptions.cs Revises resource ID guidance.
OptimizationSetup.cs Updates optimization terminology.
DiskRecommendationSummary.cs Defines the new summary model.
CostSavingsResult.cs Adds disk summary output.
CostSavingsRecommendation.cs Updates model documentation.
AlternativeRecommendation.cs Updates model terminology.
RecommendationListCommand.cs Supports optional scope and summary output.
RecommendationExplainCommand.cs Revises tool description.
RecommendationAlternativesCommand.cs Revises tool description.
OptimizationJsonContext.cs Registers the summary for AOT serialization.
e2eTestPrompts.md Adds an all-subscriptions prompt.
azmcp-commands.md Documents optional subscription scope.
optimization-tool-update.yaml Records user-facing changes.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sanjaytholanim

Copy link
Copy Markdown
Contributor Author

Updated changes with feedback from copilot

@msalaman msalaman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes look good, given that is adding ArmClient usage I think we should hold off on merging this change until this PR is merged #3884

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants