Skip to content

Migrate Best Practices tools to new tool design#2951

Open
alzimmermsft wants to merge 2 commits into
microsoft:mainfrom
alzimmermsft:MigrateBestPracticesToNewToolDesign
Open

Migrate Best Practices tools to new tool design#2951
alzimmermsft wants to merge 2 commits into
microsoft:mainfrom
alzimmermsft:MigrateBestPracticesToNewToolDesign

Conversation

@alzimmermsft

Copy link
Copy Markdown
Contributor

What does this PR do?

Migrates Best Practices tools to new design where Register and Bind options are based on Option attributes.

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, 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

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

This PR migrates the Azure Best Practices and Azure Terraform Best Practices tools to the newer command/option design where options are registered/bound via [Option] attributes and commands use BaseCommand<TOptions, TResult>.

Changes:

  • Switched best-practices commands to the BaseCommand<TOptions, TResult> execution model (options bound as POCOs, no ParseResult binding in tool code).
  • Replaced System.CommandLine option-definition scaffolding with [Option] attributes and removed related GlobalUsings.cs / option definition types.
  • Simplified JSON context declaration and removed direct System.CommandLine package references from the tool projects.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.AzureTerraformBestPractices/src/GlobalUsings.cs Removes global System.CommandLine using (no longer needed by tool code).
tools/Azure.Mcp.Tools.AzureTerraformBestPractices/src/Commands/AzureTerraformBestPracticesGetCommand.cs Migrates command to BaseCommand<EmptyOptions, List<string>> signature.
tools/Azure.Mcp.Tools.AzureTerraformBestPractices/src/Azure.Mcp.Tools.AzureTerraformBestPractices.csproj Uses $(RepoRoot) project reference and removes direct System.CommandLine package reference.
tools/Azure.Mcp.Tools.AzureBestPractices/src/Options/BestPracticesOptions.cs Introduces [Option] attributes for resource/action binding.
tools/Azure.Mcp.Tools.AzureBestPractices/src/Options/BestPracticesOptionDefinitions.cs Removes legacy option-definition class.
tools/Azure.Mcp.Tools.AzureBestPractices/src/GlobalUsings.cs Removes global System.CommandLine using (no longer needed by tool code).
tools/Azure.Mcp.Tools.AzureBestPractices/src/Commands/BestPracticesCommand.cs Migrates command to options-based execution and moves validation into ValidateOptions.
tools/Azure.Mcp.Tools.AzureBestPractices/src/Commands/AzureBestPracticesJsonContext.cs Converts JSON context to file-scoped partial type declaration.
tools/Azure.Mcp.Tools.AzureBestPractices/src/Commands/AIAppBestPracticesCommand.cs Migrates command to BaseCommand<EmptyOptions, List<string>> signature.
tools/Azure.Mcp.Tools.AzureBestPractices/src/Azure.Mcp.Tools.AzureBestPractices.csproj Uses $(RepoRoot) project reference and removes direct System.CommandLine package reference.
Comments suppressed due to low confidence (1)

tools/Azure.Mcp.Tools.AzureTerraformBestPractices/src/Commands/AzureTerraformBestPracticesGetCommand.cs:47

  • ExecuteAsync doesn’t catch exceptions / call HandleException, so failures (e.g., embedded resource lookup/read) can bubble out and bypass the standard error response path. Also, eager static initialization of the embedded text can throw during type initialization, potentially failing tool activation.
    private static readonly string s_bestPracticesText = LoadBestPracticesText();

    private static string GetBestPracticesText() => s_bestPracticesText;

    private static string LoadBestPracticesText()
    {
        Assembly assembly = typeof(AzureTerraformBestPracticesGetCommand).Assembly;
        string resourceName = EmbeddedResourceHelper.FindEmbeddedResource(assembly, "terraform-best-practices-for-azure.txt");
        return EmbeddedResourceHelper.ReadEmbeddedResource(assembly, resourceName);
    }

    public override Task<CommandResponse> ExecuteAsync(CommandContext context, EmptyOptions options, CancellationToken cancellationToken)
    {
        var bestPractices = GetBestPracticesText();
        context.Response.Status = HttpStatusCode.OK;
        context.Response.Results = ResponseResult.Create([bestPractices], AzureTerraformBestPracticesJsonContext.Default.ListString);
        context.Response.Message = string.Empty;
        return Task.FromResult(context.Response);
    }

@alzimmermsft alzimmermsft enabled auto-merge (squash) June 25, 2026 21:20
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.

2 participants