Skip to content

Onboard Azure Advisor MCP Tool - Apply Advisor Recommendations#2686

Open
ankiga-MSFT wants to merge 17 commits into
microsoft:mainfrom
ankiga-MSFT:ankiga-MSFT/advisor-mcp-apply-recommendations
Open

Onboard Azure Advisor MCP Tool - Apply Advisor Recommendations#2686
ankiga-MSFT wants to merge 17 commits into
microsoft:mainfrom
ankiga-MSFT:ankiga-MSFT/advisor-mcp-apply-recommendations

Conversation

@ankiga-MSFT
Copy link
Copy Markdown
Member

@ankiga-MSFT ankiga-MSFT commented May 20, 2026

What does this PR do?

Add Azure Advisor MCP Tool - Apply Advisor Recommendations

GitHub issue number?

2685

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

Copy link
Copy Markdown
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

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/*.json rule 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.

Comment thread tools/Azure.Mcp.Tools.Advisor/src/Resources/web_serverfarms.json Outdated
Comment thread servers/Azure.Mcp.Server/docs/azmcp-commands.md Outdated
@ankiga-MSFT
Copy link
Copy Markdown
Member Author

Results from Tool description evaluator run -

🎯 Filtering prompts to area: Advisor
📝 Using default prompts file (e2eTestPrompts.md) for Azure.Mcp.Server
💾 Saved prompts to prompts.json
🧪 Tested 5 prompts:
📊 Top choice: 100.0%
💪 Very High confidence (≥0.8): 0.0%
🎯 High confidence (≥0.7): 0.0%
✅ Good confidence (≥0.6): 100.0%
👍 Fair confidence (≥0.5): 100.0%
👌 Acceptable confidence (≥0.4): 100.0%
⭐ Top + acceptable confidence (≥0.4): 100.0%
🎯 Tool selection analysis completed
📊 Results written to: D:\msft-advisor-mcp\eng\tools\ToolDescriptionEvaluator\results.md
⏱️ Total execution time: 14.0659464s

Expected Tool: advisor_recommendation_apply
Prompt: Apply Advisor recommendations to this ARM template

Results

Rank Score Tool Status
1 0.632157 advisor_recommendation_apply EXPECTED
2 0.523744 advisor_recommendation_list
3 0.459641 azureterraformbestpractices_get
4 0.435818 deploy_pipeline_guidance_get
5 0.429113 get_azure_bestpractices_get

Expected Tool: advisor_recommendation_apply
Prompt: Apply Advisor recommendations to this Terraform file for Storage Account

Results

Rank Score Tool Status
1 0.617697 advisor_recommendation_apply EXPECTED
2 0.508354 azureterraformbestpractices_get
3 0.504128 fileshares_rec
4 0.473977 advisor_recommendation_list
5 0.413549 azurebackup_vault_update

1 similar comment
@ankiga-MSFT
Copy link
Copy Markdown
Member Author

Results from Tool description evaluator run -

🎯 Filtering prompts to area: Advisor
📝 Using default prompts file (e2eTestPrompts.md) for Azure.Mcp.Server
💾 Saved prompts to prompts.json
🧪 Tested 5 prompts:
📊 Top choice: 100.0%
💪 Very High confidence (≥0.8): 0.0%
🎯 High confidence (≥0.7): 0.0%
✅ Good confidence (≥0.6): 100.0%
👍 Fair confidence (≥0.5): 100.0%
👌 Acceptable confidence (≥0.4): 100.0%
⭐ Top + acceptable confidence (≥0.4): 100.0%
🎯 Tool selection analysis completed
📊 Results written to: D:\msft-advisor-mcp\eng\tools\ToolDescriptionEvaluator\results.md
⏱️ Total execution time: 14.0659464s

Expected Tool: advisor_recommendation_apply
Prompt: Apply Advisor recommendations to this ARM template

Results

Rank Score Tool Status
1 0.632157 advisor_recommendation_apply EXPECTED
2 0.523744 advisor_recommendation_list
3 0.459641 azureterraformbestpractices_get
4 0.435818 deploy_pipeline_guidance_get
5 0.429113 get_azure_bestpractices_get

Expected Tool: advisor_recommendation_apply
Prompt: Apply Advisor recommendations to this Terraform file for Storage Account

Results

Rank Score Tool Status
1 0.617697 advisor_recommendation_apply EXPECTED
2 0.508354 azureterraformbestpractices_get
3 0.504128 fileshares_rec
4 0.473977 advisor_recommendation_list
5 0.413549 azurebackup_vault_update

Comment on lines +25 to +28
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.";
Copy link
Copy Markdown
Contributor

@alzimmermsft alzimmermsft May 22, 2026

Choose a reason for hiding this comment

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

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.

Comment on lines +90 to +95
if (string.IsNullOrEmpty(options.Resource))
{
context.Response.Status = HttpStatusCode.BadRequest;
context.Response.Message = "Resource parameter is required.";
return Task.FromResult(context.Response);
}
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.

This isn't needed as this is already handled in RegisterOptions's validator

Comment on lines +118 to +121
if (string.IsNullOrEmpty(resourceFileName))
{
throw new ArgumentException("Resource file name cannot be null or empty.", nameof(resourceFileName));
}
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.

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);
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.

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": [
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.

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.

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

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants