Added optimization tools - #3429
Conversation
|
Copilot resolve the merge conflicts in this pull request |
There was a problem hiding this comment.
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.
| if (string.IsNullOrWhiteSpace(options.ResourceId)) | ||
| { | ||
| validationResult.Errors.Add("--resource-id is required."); | ||
| } | ||
| else if (!ArmResourceId.IsValid(options.ResourceId)) | ||
| { | ||
| validationResult.Errors.Add(OptimizationStrings.ErrorInvalidResourceId); | ||
| } |
| 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."; |
| { | ||
| "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": { |
| <IsTestProject>true</IsTestProject> | ||
| <OutputType>Exe</OutputType> | ||
| <HasLiveTests>false</HasLiveTests> | ||
| <HasUnitTests>true</HasUnitTests> |
…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>
Resolved in cfb860a / d657e72. Merged |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
What does this PR do?
Adds a new Optimization toolset (
optimizationnamespace) to the Azure MCP Server that surfaces Azure Advisor cost-optimization recommendations and utilization insights. The toolset adds three read-only tools under therecommendationgroup: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 overresourcecontainers— the tools do not enumerate all subscriptions and instruct the agent not to call thesubscription listtool first (avoids high token usage).All new services inject
IHttpClientFactory/IAzureService, useSystem.Text.Jsonwith AOT-safe serialization contexts, and follow the two-generic command pattern.GitHub issue number?
https://github.com/microsoft/mcp-pr/issues/598Pre-merge Checklist
servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationREADME.mdchanges running the script./eng/scripts/Process-PackageReadMe.ps1. See Package READMEToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.jsonbreaking-changelabelservers/Azure.Mcp.Server/docs/azmcp-commands.md./eng/scripts/Update-AzCommandsMetadata.ps1to update tool metadata inazmcp-commands.md(required for CI)servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test PipelineReference documentation