From 693881e8f50448a553aefa069b3354619637a7cb Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 12 Jun 2026 16:12:39 -0400 Subject: [PATCH 1/2] Migrate App Lens tools to new tool design --- .../changelog-entries/1781295131142.yaml | 3 ++ .../Resource/ResourceDiagnoseCommand.cs | 34 +------------ .../src/GlobalUsings.cs | 5 -- .../src/Models/AppLensJsonContext.cs | 1 + .../src/Models/AppLensModels.cs | 2 + .../src/Options/AppLensOptionDefinitions.cs | 48 ------------------- .../Resource/ResourceDiagnoseOptions.cs | 17 +++++-- .../src/Services/AppLensService.cs | 1 + 8 files changed, 23 insertions(+), 88 deletions(-) create mode 100644 servers/Azure.Mcp.Server/changelog-entries/1781295131142.yaml delete mode 100644 tools/Azure.Mcp.Tools.AppLens/src/GlobalUsings.cs delete mode 100644 tools/Azure.Mcp.Tools.AppLens/src/Options/AppLensOptionDefinitions.cs diff --git a/servers/Azure.Mcp.Server/changelog-entries/1781295131142.yaml b/servers/Azure.Mcp.Server/changelog-entries/1781295131142.yaml new file mode 100644 index 0000000000..1e69686c30 --- /dev/null +++ b/servers/Azure.Mcp.Server/changelog-entries/1781295131142.yaml @@ -0,0 +1,3 @@ +changes: + - section: "Breaking Changes" + description: "Removed unused parameters from App Lens tools." diff --git a/tools/Azure.Mcp.Tools.AppLens/src/Commands/Resource/ResourceDiagnoseCommand.cs b/tools/Azure.Mcp.Tools.AppLens/src/Commands/Resource/ResourceDiagnoseCommand.cs index 2820d22627..a8e0d4310b 100644 --- a/tools/Azure.Mcp.Tools.AppLens/src/Commands/Resource/ResourceDiagnoseCommand.cs +++ b/tools/Azure.Mcp.Tools.AppLens/src/Commands/Resource/ResourceDiagnoseCommand.cs @@ -2,12 +2,10 @@ // Licensed under the MIT License. using Azure.Mcp.Tools.AppLens.Models; -using Azure.Mcp.Tools.AppLens.Options; using Azure.Mcp.Tools.AppLens.Options.Resource; using Azure.Mcp.Tools.AppLens.Services; using Microsoft.Extensions.Logging; using Microsoft.Mcp.Core.Commands; -using Microsoft.Mcp.Core.Extensions; using Microsoft.Mcp.Core.Models.Command; namespace Azure.Mcp.Tools.AppLens.Commands.Resource; @@ -29,43 +27,15 @@ namespace Azure.Mcp.Tools.AppLens.Commands.Resource; Secret = false, LocalRequired = false)] public sealed class ResourceDiagnoseCommand(ILogger logger, IAppLensService appLensService) - : GlobalCommand + : BaseCommand { private readonly ILogger _logger = logger; private readonly IAppLensService _appLensService = appLensService; - protected override void RegisterOptions(Command command) - { - base.RegisterOptions(command); - command.Options.Add(AppLensOptionDefinitions.Subscription); - command.Options.Add(AppLensOptionDefinitions.ResourceGroup); - command.Options.Add(AppLensOptionDefinitions.ResourceType); - command.Options.Add(AppLensOptionDefinitions.Resource); - command.Options.Add(AppLensOptionDefinitions.Question); - } - - protected override ResourceDiagnoseOptions BindOptions(ParseResult parseResult) - { - var options = base.BindOptions(parseResult); - options.Subscription = parseResult.GetValueOrDefault(AppLensOptionDefinitions.Subscription.Name); - options.ResourceGroup = parseResult.GetValueOrDefault(AppLensOptionDefinitions.ResourceGroup.Name); - options.Question = parseResult.GetValueOrDefault(AppLensOptionDefinitions.Question.Name) ?? string.Empty; - options.Resource = parseResult.GetValueOrDefault(AppLensOptionDefinitions.Resource.Name) ?? string.Empty; - options.ResourceType = parseResult.GetValueOrDefault(AppLensOptionDefinitions.ResourceType.Name); - return options; - } - - public override async Task ExecuteAsync(CommandContext context, ParseResult parseResult, CancellationToken cancellationToken) + public override async Task ExecuteAsync(CommandContext context, ResourceDiagnoseOptions options, CancellationToken cancellationToken) { try { - if (!Validate(parseResult.CommandResult, context.Response).IsValid) - { - return context.Response; - } - - ResourceDiagnoseOptions options = BindOptions(parseResult); - _logger.LogInformation("Diagnosing resource. Question: {Question}, Resource: {Resource}, Options: {Options}", options.Question, options.Resource, options); diff --git a/tools/Azure.Mcp.Tools.AppLens/src/GlobalUsings.cs b/tools/Azure.Mcp.Tools.AppLens/src/GlobalUsings.cs deleted file mode 100644 index 14a017b104..0000000000 --- a/tools/Azure.Mcp.Tools.AppLens/src/GlobalUsings.cs +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -global using System.CommandLine; -global using System.Text.Json; diff --git a/tools/Azure.Mcp.Tools.AppLens/src/Models/AppLensJsonContext.cs b/tools/Azure.Mcp.Tools.AppLens/src/Models/AppLensJsonContext.cs index 83cafdd13b..a979a0c578 100644 --- a/tools/Azure.Mcp.Tools.AppLens/src/Models/AppLensJsonContext.cs +++ b/tools/Azure.Mcp.Tools.AppLens/src/Models/AppLensJsonContext.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System.Text.Json; using System.Text.Json.Serialization; namespace Azure.Mcp.Tools.AppLens.Models; diff --git a/tools/Azure.Mcp.Tools.AppLens/src/Models/AppLensModels.cs b/tools/Azure.Mcp.Tools.AppLens/src/Models/AppLensModels.cs index f1ea50126d..c4e3720559 100644 --- a/tools/Azure.Mcp.Tools.AppLens/src/Models/AppLensModels.cs +++ b/tools/Azure.Mcp.Tools.AppLens/src/Models/AppLensModels.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System.Text.Json; + namespace Azure.Mcp.Tools.AppLens.Models; /// diff --git a/tools/Azure.Mcp.Tools.AppLens/src/Options/AppLensOptionDefinitions.cs b/tools/Azure.Mcp.Tools.AppLens/src/Options/AppLensOptionDefinitions.cs deleted file mode 100644 index 6f626b72a7..0000000000 --- a/tools/Azure.Mcp.Tools.AppLens/src/Options/AppLensOptionDefinitions.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -namespace Azure.Mcp.Tools.AppLens.Options; - -public static class AppLensOptionDefinitions -{ - public const string QuestionName = "question"; - public const string ResourceName = "resource"; - public const string ResourceTypeName = "resource-type"; - public const string ResourceGroupName = "resource-group"; - public const string SubscriptionName = "subscription"; - - public static readonly Option Question = new( - $"--{QuestionName}") - { - Description = "User question", - Required = true - }; - - public static readonly Option Resource = new( - $"--{ResourceName}") - { - Description = "The name of the resource to investigate or diagnose", - Required = true - }; - - public static readonly Option Subscription = new( - $"--{SubscriptionName}") - { - Description = "Azure subscription ID or name. Provide this when disambiguating between multiple resources of the same name.", - Required = false - }; - - public static readonly Option ResourceGroup = new( - $"--{ResourceGroupName}") - { - Description = "Azure resource group name. Provide this when disambiguating between multiple resources of the same name.", - Required = false - }; - - public static readonly Option ResourceType = new( - $"--{ResourceTypeName}") - { - Description = "Resource type. Provide this when disambiguating between multiple resources of the same name.", - Required = false - }; -} diff --git a/tools/Azure.Mcp.Tools.AppLens/src/Options/Resource/ResourceDiagnoseOptions.cs b/tools/Azure.Mcp.Tools.AppLens/src/Options/Resource/ResourceDiagnoseOptions.cs index 18a8cb97eb..957f0bfbcd 100644 --- a/tools/Azure.Mcp.Tools.AppLens/src/Options/Resource/ResourceDiagnoseOptions.cs +++ b/tools/Azure.Mcp.Tools.AppLens/src/Options/Resource/ResourceDiagnoseOptions.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using Azure.Mcp.Core.Options; using Microsoft.Mcp.Core.Options; namespace Azure.Mcp.Tools.AppLens.Options.Resource; @@ -8,25 +9,35 @@ namespace Azure.Mcp.Tools.AppLens.Options.Resource; /// /// Options for the AppLens resource diagnose command. /// -public class ResourceDiagnoseOptions : GlobalOptions +public sealed class ResourceDiagnoseOptions { + [Option(OptionDescriptions.Tenant)] + public string? Tenant { get; set; } + + [Option("Azure resource group name. Provide this when disambiguating between multiple resources of the same name.")] + public string? ResourceGroup { get; set; } + /// /// The user's question for diagnosis. /// - public string Question { get; set; } = string.Empty; + [Option("User question")] + public required string Question { get; set; } /// /// The name of the resource to diagnose. /// - public string Resource { get; set; } = string.Empty; + [Option("The name of the resource to investigate or diagnose")] + public required string Resource { get; set; } /// /// The Resource Type of the resource to diagnose. This is optional and used to disambiguate between multiple resources with the same name. /// + [Option("Resource type. Provide this when disambiguating between multiple resources of the same name.")] public string? ResourceType { get; set; } /// /// The subscription of the resource to diagnose. This is optional and used to disambiguate between multiple resources with the same name. /// + [Option("Azure subscription ID or name. Provide this when disambiguating between multiple resources of the same name.")] public string? Subscription { get; set; } } diff --git a/tools/Azure.Mcp.Tools.AppLens/src/Services/AppLensService.cs b/tools/Azure.Mcp.Tools.AppLens/src/Services/AppLensService.cs index 554521c1e1..701c6f6377 100644 --- a/tools/Azure.Mcp.Tools.AppLens/src/Services/AppLensService.cs +++ b/tools/Azure.Mcp.Tools.AppLens/src/Services/AppLensService.cs @@ -5,6 +5,7 @@ using System.IdentityModel.Tokens.Jwt; using System.Runtime.CompilerServices; using System.Text; +using System.Text.Json; using System.Threading.Channels; using Azure.Core; using Azure.Mcp.Core.Services.Azure; From f35370c1a9f0c1b97a0cc0dca3a0500ee9a483de Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 12 Jun 2026 17:26:00 -0400 Subject: [PATCH 2/2] Fix linting --- .../src/Options/Resource/ResourceDiagnoseOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Azure.Mcp.Tools.AppLens/src/Options/Resource/ResourceDiagnoseOptions.cs b/tools/Azure.Mcp.Tools.AppLens/src/Options/Resource/ResourceDiagnoseOptions.cs index 957f0bfbcd..4d127e2671 100644 --- a/tools/Azure.Mcp.Tools.AppLens/src/Options/Resource/ResourceDiagnoseOptions.cs +++ b/tools/Azure.Mcp.Tools.AppLens/src/Options/Resource/ResourceDiagnoseOptions.cs @@ -16,7 +16,7 @@ public sealed class ResourceDiagnoseOptions [Option("Azure resource group name. Provide this when disambiguating between multiple resources of the same name.")] public string? ResourceGroup { get; set; } - + /// /// The user's question for diagnosis. ///