Migrate Best Practices tools to new tool design#2951
Open
alzimmermsft wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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, noParseResultbinding in tool code). - Replaced
System.CommandLineoption-definition scaffolding with[Option]attributes and removed relatedGlobalUsings.cs/ option definition types. - Simplified JSON context declaration and removed direct
System.CommandLinepackage 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
ExecuteAsyncdoesn’t catch exceptions / callHandleException, 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);
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Migrates Best Practices tools to new design where Register and Bind options are based on
Optionattributes.GitHub issue number?
[Link to the GitHub issue this PR addresses]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