Skip to content

Added optimization tools - #3429

Open
sanjaytholanim wants to merge 5 commits into
mainfrom
smanojkumar/onboard-optimization-mcp-tools
Open

Added optimization tools#3429
sanjaytholanim wants to merge 5 commits into
mainfrom
smanojkumar/onboard-optimization-mcp-tools

Conversation

@sanjaytholanim

Copy link
Copy Markdown

What does this PR do?

Adds a new Optimization toolset (optimization namespace) to the Azure MCP Server that surfaces Azure Advisor cost-optimization recommendations and utilization insights. The toolset adds three read-only tools under the recommendation group:

  • optimization recommendation list — Returns the top Azure Advisor cost-saving recommendations for a subscription via a curated Azure Resource Graph (ARG) query, ranked by impact and currency-normalized annual savings (--top, default 100, max 1000).
  • optimization recommendation alternatives — Returns alternative resize/SKU options carried on an Advisor right-size recommendation for a VM/VMSS, with inclusion/exclusion filters for SKU, VM series, and processor type.
  • optimization recommendation explain — Explains a specific recommendation and projects current-vs-target-SKU utilization time-series (CPU, memory, network) from Azure Monitor, with target SKU specs from the Microsoft.Compute Resource SKUs API.

Subscription resolution is handled internally: a subscription name or id can be passed to --subscription, and a name is resolved to its id with a single targeted ARG lookup over resourcecontainers — the tools do not enumerate all subscriptions and instruct the agent not to call the subscription list tool first (avoids high token usage).

All new services inject IHttpClientFactory/IAzureService, use System.Text.Json with AOT-safe serialization contexts, and follow the two-generic command pattern.

image image

GitHub issue number?

https://github.com/microsoft/mcp-pr/issues/598

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, 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
    • For renamed tools, follow the Tool Rename Checklist and tag the PR with the breaking-change label
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • 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

Reference documentation

@sanjaytholanim

Copy link
Copy Markdown
Author

Copilot resolve the merge conflicts in this pull request

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.

Pull request overview

Adds a new Optimization toolset (optimization namespace) to the Azure MCP Server, exposing Azure Advisor cost-optimization recommendations plus an “explain” flow that projects utilization from Azure Monitor and compares VM/VMSS SKUs.

Changes:

  • Introduces optimization recommendation {list|alternatives|explain} commands, options, models, and supporting services (ARG queries, Monitor metrics, Compute SKUs lookup).
  • Registers the new toolset in the server and adds a consolidated tool mapping for it.
  • Adds unit tests plus docs/changelog updates for discoverability and prompting.

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.Optimization/tests/Azure.Mcp.Tools.Optimization.Tests/Services/ArmResourceIdTests.cs Unit tests for Advisor suffix stripping helper.
tools/Azure.Mcp.Tools.Optimization/tests/Azure.Mcp.Tools.Optimization.Tests/Recommendation/RecommendationListCommandTests.cs Unit tests for recommendation list.
tools/Azure.Mcp.Tools.Optimization/tests/Azure.Mcp.Tools.Optimization.Tests/Recommendation/RecommendationExplainCommandTests.cs Unit tests for recommendation explain.
tools/Azure.Mcp.Tools.Optimization/tests/Azure.Mcp.Tools.Optimization.Tests/Recommendation/RecommendationAlternativesCommandTests.cs Unit tests for recommendation alternatives.
tools/Azure.Mcp.Tools.Optimization/tests/Azure.Mcp.Tools.Optimization.Tests/Azure.Mcp.Tools.Optimization.Tests.csproj Test project definition for Optimization toolset.
tools/Azure.Mcp.Tools.Optimization/src/Services/RecommendationUtilizationProjector.cs Projects current vs target utilization series.
tools/Azure.Mcp.Tools.Optimization/src/Services/OptimizationStrings.cs Shared user/agent-facing strings used by tools.
tools/Azure.Mcp.Tools.Optimization/src/Services/OptimizationService.cs Core service: ARG queries, subscription-name resolution, explain flow orchestration.
tools/Azure.Mcp.Tools.Optimization/src/Services/OptimizationMonitorClient.cs Azure Monitor metrics and VM Insights memory fallback client.
tools/Azure.Mcp.Tools.Optimization/src/Services/OptimizationKqlQueries.cs Centralizes ARG KQL queries used by the toolset.
tools/Azure.Mcp.Tools.Optimization/src/Services/OptimizationComputeSkuClient.cs ARM/Compute REST calls to compare current vs target VM SKU specs.
tools/Azure.Mcp.Tools.Optimization/src/Services/IOptimizationService.cs Service interface for commands to consume.
tools/Azure.Mcp.Tools.Optimization/src/Services/ArmResourceId.cs ARM ID validation and Advisor recommendation suffix stripping.
tools/Azure.Mcp.Tools.Optimization/src/Services/AlternativeRecommendationsArgParser.cs Parses alternative recommendation payload from ARG results.
tools/Azure.Mcp.Tools.Optimization/src/Services/AlternativeMarkdownBuilder.cs Renders markdown summary/table for alternatives output.
tools/Azure.Mcp.Tools.Optimization/src/Services/AlternativeFilters.cs Parses and applies include/exclude filters for alternatives.
tools/Azure.Mcp.Tools.Optimization/src/Options/Recommendation/RecommendationListOptions.cs CLI/tool options for list.
tools/Azure.Mcp.Tools.Optimization/src/Options/Recommendation/RecommendationExplainOptions.cs CLI/tool options for explain.
tools/Azure.Mcp.Tools.Optimization/src/Options/Recommendation/RecommendationAlternativesOptions.cs CLI/tool options for alternatives.
tools/Azure.Mcp.Tools.Optimization/src/OptimizationSetup.cs DI + command registration for the new area.
tools/Azure.Mcp.Tools.Optimization/src/Models/VmSkuSpecifications.cs Models for current/target SKU comparison.
tools/Azure.Mcp.Tools.Optimization/src/Models/UtilizationView.cs Enum controlling detail/trend utilization output.
tools/Azure.Mcp.Tools.Optimization/src/Models/RecommendationUtilization.cs Utilization time-series models returned by explain.
tools/Azure.Mcp.Tools.Optimization/src/Models/RecommendationExplanationResult.cs Explain tool result shape.
tools/Azure.Mcp.Tools.Optimization/src/Models/RecommendationExplanation.cs Internal projection inputs for utilization computations.
tools/Azure.Mcp.Tools.Optimization/src/Models/CostSavingsRecommendation.cs List tool recommendation model.
tools/Azure.Mcp.Tools.Optimization/src/Models/AzureMonitorUtilizationData.cs Raw utilization series container.
tools/Azure.Mcp.Tools.Optimization/src/Models/AlternativeRecommendation.cs Alternatives model.
tools/Azure.Mcp.Tools.Optimization/src/Commands/Recommendation/RecommendationListCommand.cs Implements optimization recommendation list.
tools/Azure.Mcp.Tools.Optimization/src/Commands/Recommendation/RecommendationExplainCommand.cs Implements optimization recommendation explain.
tools/Azure.Mcp.Tools.Optimization/src/Commands/Recommendation/RecommendationAlternativesCommand.cs Implements optimization recommendation alternatives.
tools/Azure.Mcp.Tools.Optimization/src/Commands/OptimizationJsonContext.cs Source-gen JSON context registration for AOT-safe serialization.
tools/Azure.Mcp.Tools.Optimization/src/Azure.Mcp.Tools.Optimization.csproj Toolset project definition.
tools/Azure.Mcp.Tools.Optimization/src/AssemblyInfo.cs InternalsVisibleTo for test access.
servers/Azure.Mcp.Server/src/Resources/consolidated-tools.json Adds consolidated tool mapping for optimization tools.
servers/Azure.Mcp.Server/src/Program.cs Registers Optimization area in server startup.
servers/Azure.Mcp.Server/docs/e2eTestPrompts.md Adds e2e prompts for optimization tools.
servers/Azure.Mcp.Server/docs/azmcp-commands.md Documents new azmcp optimization recommendation ... commands.
servers/Azure.Mcp.Server/changelog-entries/optimization-tools.yaml Changelog entry for the new toolset.
servers/Azure.Mcp.Server/Azure.Mcp.Server.slnx Adds Optimization projects to server solution.
Microsoft.Mcp.slnx Adds Optimization projects to root solution.
.github/CODEOWNERS Adds code owners/labels for Optimization toolset.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +66 to +73
if (string.IsNullOrWhiteSpace(options.ResourceId))
{
validationResult.Errors.Add("--resource-id is required.");
}
else if (!ArmResourceId.IsValid(options.ResourceId))
{
validationResult.Errors.Add(OptimizationStrings.ErrorInvalidResourceId);
}
Comment on lines +14 to +21
public const string ExplanationRenderingInstructions =
"ACTION REQUIRED NOW: Immediately render the recentUtilization (and longTermUtilization when present) series as an " +
"inline line/time-series chart in this reply, without asking for permission. Put the timestamp on the x-axis and " +
"percentage on the y-axis; draw separate lines for current versus target CPU, used-memory, and network utilization; " +
"and mark the threshold levels from thresholds. Use your native inline chart/visualization capability \u2014 do NOT " +
"write HTML, generate images, create files, run code, or link to external tools. After the chart, briefly summarize " +
"the recommendation, the current-versus-target configuration, the max-utilization comparison, and any threshold " +
"risks. If inline chart rendering is not possible at all, skip the chart \u2014 do not create any files or artifacts.";
Comment on lines +958 to +961
{
"name": "get_azure_optimization_recommendations",
"description": "Get Azure optimization recommendations. List top Azure Advisor cost-saving recommendations for a subscription ranked by impact and currency-normalized annual savings, get alternative compute resize/SKU options for a virtual machine or virtual machine scale set with optional include/exclude filters, and explain a recommendation with current-versus-target-SKU utilization time-series projected from Azure Monitor.",
"toolMetadata": {
Comment on lines +3 to +6
<IsTestProject>true</IsTestProject>
<OutputType>Exe</OutputType>
<HasLiveTests>false</HasLiveTests>
<HasUnitTests>true</HasUnitTests>
Copilot AI and others added 2 commits August 28, 2026 23:10
…ptimization-mcp-tools

# Conflicts:
#	servers/Azure.Mcp.Server/docs/azmcp-commands.md

Co-authored-by: sanjaytholanim <198103903+sanjaytholanim@users.noreply.github.com>
…mpatibility

Co-authored-by: sanjaytholanim <198103903+sanjaytholanim@users.noreply.github.com>

Copilot AI commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Copilot resolve the merge conflicts in this pull request

Resolved in cfb860a / d657e72. Merged main in and resolved the single conflict in azmcp-commands.md by keeping main's formatting and re-inserting the Optimization section. Also updated the Optimization toolset to drop RetryPolicyOptions usage from options/commands/service/tests, matching main's recent repo-wide removal of that pattern.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server-Azure.Mcp Azure.Mcp.Server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants