Onboard Azure Advisor MCP Tool - Apply Advisor Recommendations#2686
Onboard Azure Advisor MCP Tool - Apply Advisor Recommendations#2686ankiga-MSFT wants to merge 17 commits into
Conversation
…://github.com/ankiga-MSFT/msft-advisor-mcp into ankiga-MSFT/advisor-mcp-apply-recommendations
…://github.com/ankiga-MSFT/msft-advisor-mcp into ankiga-MSFT/advisor-mcp-apply-recommendations
There was a problem hiding this comment.
Pull request overview
This PR onboards an Azure Advisor MCP tool command (azmcp advisor recommendation apply) that returns embedded “apply recommendation” rule definitions for a set of Azure resource types, along with unit tests and server/docs registration.
Changes:
- Added
RecommendationApplyCommand(+ options + JSON source-gen support) to return embedded rule JSON by--resource. - Added embedded
Resources/*.jsonrule definitions for multiple Azure resource types. - Wired the tool into Azure MCP Server metadata/docs and added unit tests for the new command.
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.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/Azure.Mcp.Tools.Advisor/src/Commands/Recommendation/RecommendationApplyCommand.cs | New “apply” command that validates --resource, loads embedded JSON, and caches results. |
| tools/Azure.Mcp.Tools.Advisor/src/Options/Recommendation/RecommendationApplyOptions.cs | Options POCO for the apply command. |
| tools/Azure.Mcp.Tools.Advisor/src/Options/Recommendation/RecommendationApplyOptionDefinitions.cs | Defines the --resource option and help text. |
| tools/Azure.Mcp.Tools.Advisor/src/Commands/AdvisorJsonContext.cs | Adds source-gen support for List<string> responses. |
| tools/Azure.Mcp.Tools.Advisor/src/AdvisorSetup.cs | Registers the new command in DI and command group. |
| tools/Azure.Mcp.Tools.Advisor/tests/Azure.Mcp.Tools.Advisor.Tests/Recommendation/RecommendationApplyCommandTests.cs | Unit tests covering metadata, validation, deserialization, and caching behavior. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/aad_domainservices.json | New embedded rule definitions for Entra Domain Services. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/apimanagement_service.json | New embedded rule definitions for API Management. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/cognitiveservices_accounts.json | New embedded rule definitions for Cognitive Services accounts. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/compute_virtualmachines.json | New embedded rule definitions for VMs. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/compute_virtualmachinescalesets.json | New embedded rule definitions for VM scale sets. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/containerregistry_registries.json | New embedded rule definitions for ACR. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/containerservice_managedclusters.json | New embedded rule definitions for AKS clusters. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/dbforpostgresql_flexibleservers.json | New embedded rule definitions for PostgreSQL flexible servers. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/documentdb_databaseaccounts.json | New embedded rule definitions for Cosmos DB accounts. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/keyvault_vaults.json | New embedded rule definitions for Key Vault. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/kubernetes_connectedclusters.json | New embedded rule definitions for Arc connected clusters. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/kubernetesconfiguration_extensions.json | New embedded rule definitions for Kubernetes extensions. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/netapp_volumes.json | New embedded rule definitions for NetApp volumes. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/network_applicationgatewaywebapplicationfirewallpolicies.json | New embedded rule definitions for App Gateway WAF policies. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/network_expressrouteports.json | New embedded rule definitions for ExpressRoute ports. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/network_frontdoorwebapplicationfirewallpolicies.json | New embedded rule definitions for Front Door WAF policies. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/sql_managedinstances.json | New embedded rule definitions for SQL managed instances. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/storage_storageaccounts.json | New embedded rule definitions for Storage accounts. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/web_serverfarms.json | New embedded rule definitions for App Service plans. |
| tools/Azure.Mcp.Tools.Advisor/src/Resources/web_staticsites.json | New embedded rule definitions for Static Web Apps. |
| servers/Azure.Mcp.Server/src/Resources/consolidated-tools.json | Adds the new tool mapping (advisor_recommendation_apply) to the consolidated tool catalog. |
| servers/Azure.Mcp.Server/docs/azmcp-commands.md | Documents the new CLI command usage. |
|
Results from Tool description evaluator run - 🎯 Filtering prompts to area: Advisor Expected Tool: Results
Expected Tool: Results
|
1 similar comment
|
Results from Tool description evaluator run - 🎯 Filtering prompts to area: Advisor Expected Tool: Results
Expected Tool: Results
|
| public override string Name => "apply"; | ||
|
|
||
| public override string Description => | ||
| @"This tool applies advisor recommendations to create or modify IaaC files (like ARM, Terraform) for Azure resources. It returns the rules that can be applied to the IaaC file."; |
There was a problem hiding this comment.
The name and description here are a bit confusing as this tool doesn't actually apply the recommendation but returns the recommendations that are applicable to the resource.
| if (string.IsNullOrEmpty(options.Resource)) | ||
| { | ||
| context.Response.Status = HttpStatusCode.BadRequest; | ||
| context.Response.Message = "Resource parameter is required."; | ||
| return Task.FromResult(context.Response); | ||
| } |
There was a problem hiding this comment.
This isn't needed as this is already handled in RegisterOptions's validator
| if (string.IsNullOrEmpty(resourceFileName)) | ||
| { | ||
| throw new ArgumentException("Resource file name cannot be null or empty.", nameof(resourceFileName)); | ||
| } |
There was a problem hiding this comment.
This case is impossible given the guards applied before calling into this method, we could remove this
| var recommendationApplyRules = GetAdvisorRecommendationRules(resourceFileName); | ||
|
|
||
| context.Response.Status = HttpStatusCode.OK; | ||
| context.Response.Results = ResponseResult.Create([recommendationApplyRules], AdvisorJsonContext.Default.ListString); |
There was a problem hiding this comment.
Based on how GetAdvisorRecommendationRules works, recommendationApplyRules could be null. Should check for that here so we don't return [null] and instead when it is null return []
| @@ -0,0 +1,86 @@ | |||
| { | |||
| "rules": [ | |||
There was a problem hiding this comment.
Will these JSON files ever have other top-level properties in them other than rules? If not, we might want to make some slight modifications to the tool to make the tool response clearer. Right now, it's something like:
[
{
"rules": [
<one or more rules>
]
}
]We could remove the nesting here and make it:
{
"rules": [
<one or more rules>
]
}Also, if rules follows a common shape we probably want to read these JSON files as JsonElement so they can be interacted with more meaningfully in the MCP tool if they are expected to change over time.
What does this PR do?
Add Azure Advisor MCP Tool - Apply Advisor Recommendations
GitHub issue number?
2685
Pre-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 Pipeline