-
Notifications
You must be signed in to change notification settings - Fork 416
Add azmcp containerapps list command
#1981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
9
commits into
main
Choose a base branch
from
copilot/implement-issue-200-app-containers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+497
−2
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0280abd
Initial plan
Copilot af27706
Add azmcp containerapps containerapp list command
Copilot 60affb5
Address code review feedback: rename test method and improve e2e prompts
Copilot 40e6c16
Change command from containerapps containerapp list to containerapps …
Copilot 66a2ab8
Plan: Fix ConsolidatedModeTests failure by adding containerapps_list …
Copilot fe35e7f
Add containerapps_list to consolidated-tools.json and restore global.…
Copilot 13c02fd
Update tools/Azure.Mcp.Tools.ContainerApps/src/Services/ContainerApps…
ArthurMa1978 192566f
Update tools/Azure.Mcp.Tools.ContainerApps/src/Commands/ContainerApp/…
ArthurMa1978 b11ffce
Address review: save/restore AZURE_SUBSCRIPTION_ID env var in test an…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
servers/Azure.Mcp.Server/changelog-entries/1773129554713.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| changes: | ||
| - section: "Features Added" | ||
| description: "Added `azmcp containerapps list` command to list Azure Container Apps in a subscription" |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
|
|
||
| [assembly: InternalsVisibleTo("Azure.Mcp.Tools.ContainerApps.UnitTests")] | ||
| [assembly: InternalsVisibleTo("Azure.Mcp.Tools.ContainerApps.LiveTests")] |
19 changes: 19 additions & 0 deletions
19
tools/Azure.Mcp.Tools.ContainerApps/src/Azure.Mcp.Tools.ContainerApps.csproj
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <IsAotCompatible>true</IsAotCompatible> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <EmbeddedResource Include="**\Resources\*.txt" /> | ||
| <EmbeddedResource Include="**\Resources\*.json" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\core\Azure.Mcp.Core\src\Azure.Mcp.Core.csproj" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Azure.ResourceManager" /> | ||
| <PackageReference Include="Azure.ResourceManager.AppContainers" /> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" /> | ||
| <PackageReference Include="ModelContextProtocol" /> | ||
| <PackageReference Include="System.CommandLine" /> | ||
| </ItemGroup> | ||
| </Project> |
28 changes: 28 additions & 0 deletions
28
tools/Azure.Mcp.Tools.ContainerApps/src/Commands/BaseContainerAppsCommand.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using Azure.Mcp.Core.Commands.Subscription; | ||
| using Azure.Mcp.Core.Extensions; | ||
| using Azure.Mcp.Core.Models.Option; | ||
| using Microsoft.Mcp.Core.Models.Option; | ||
|
|
||
| namespace Azure.Mcp.Tools.ContainerApps.Commands; | ||
|
|
||
| public abstract class BaseContainerAppsCommand< | ||
| [DynamicallyAccessedMembers(TrimAnnotations.CommandAnnotations)] TOptions> | ||
| : SubscriptionCommand<TOptions> where TOptions : SubscriptionOptions, new() | ||
| { | ||
| protected override void RegisterOptions(Command command) | ||
| { | ||
| base.RegisterOptions(command); | ||
| command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsOptional()); | ||
| } | ||
|
|
||
| protected override TOptions BindOptions(ParseResult parseResult) | ||
| { | ||
| var options = base.BindOptions(parseResult); | ||
| options.ResourceGroup ??= parseResult.GetValueOrDefault<string>(OptionDefinitions.Common.ResourceGroup.Name); | ||
| return options; | ||
| } | ||
| } |
73 changes: 73 additions & 0 deletions
73
tools/Azure.Mcp.Tools.ContainerApps/src/Commands/ContainerApp/ContainerAppListCommand.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Mcp.Tools.ContainerApps.Options.ContainerApp; | ||
| using Azure.Mcp.Tools.ContainerApps.Services; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Mcp.Core.Commands; | ||
| using Microsoft.Mcp.Core.Models.Command; | ||
|
|
||
| namespace Azure.Mcp.Tools.ContainerApps.Commands.ContainerApp; | ||
|
|
||
| public sealed class ContainerAppListCommand(ILogger<ContainerAppListCommand> logger, IContainerAppsService containerAppsService) : BaseContainerAppsCommand<ContainerAppListOptions> | ||
| { | ||
| private const string CommandTitle = "List Container Apps"; | ||
| private readonly ILogger<ContainerAppListCommand> _logger = logger; | ||
| private readonly IContainerAppsService _containerAppsService = containerAppsService; | ||
|
|
||
| public override string Id => "d4e5f6a7-b8c9-0d1e-2f3a-4b5c6d7e8f90"; | ||
|
|
||
| public override string Name => "list"; | ||
|
|
||
| public override string Description => | ||
| $""" | ||
| List Azure Container Apps in a subscription. Optionally filter by resource group. Each container app result | ||
| includes: name, location, resourceGroup, managedEnvironmentId, provisioningState. If no container apps are | ||
| found the tool returns null results (consistent with other list commands). | ||
| """; | ||
|
|
||
| public override string Title => CommandTitle; | ||
|
|
||
| public override ToolMetadata Metadata => new() | ||
| { | ||
| Destructive = false, | ||
| Idempotent = true, | ||
| OpenWorld = false, | ||
| ReadOnly = true, | ||
| LocalRequired = false, | ||
| Secret = false | ||
| }; | ||
|
|
||
| public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult, CancellationToken cancellationToken) | ||
| { | ||
| if (!Validate(parseResult.CommandResult, context.Response).IsValid) | ||
| { | ||
| return context.Response; | ||
| } | ||
|
|
||
| var options = BindOptions(parseResult); | ||
|
|
||
| try | ||
| { | ||
| var containerApps = await _containerAppsService.ListContainerApps( | ||
| options.Subscription!, | ||
| options.ResourceGroup, | ||
| options.Tenant, | ||
| options.RetryPolicy, | ||
| cancellationToken); | ||
|
|
||
| context.Response.Results = ResponseResult.Create(new(containerApps?.Results ?? [], containerApps?.AreResultsTruncated ?? false), ContainerAppsJsonContext.Default.ContainerAppListCommandResult); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, | ||
| "Error listing container apps. Subscription: {Subscription}, ResourceGroup: {ResourceGroup}, Options: {@Options}", | ||
| options.Subscription, options.ResourceGroup, options); | ||
| HandleException(context, ex); | ||
| } | ||
|
|
||
| return context.Response; | ||
| } | ||
|
|
||
| internal record ContainerAppListCommandResult(List<Models.ContainerAppInfo> ContainerApps, bool AreResultsTruncated); | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
tools/Azure.Mcp.Tools.ContainerApps/src/Commands/ContainerAppsJsonContext.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
| using Azure.Mcp.Tools.ContainerApps.Commands.ContainerApp; | ||
|
|
||
| namespace Azure.Mcp.Tools.ContainerApps.Commands; | ||
|
|
||
| [JsonSerializable(typeof(ContainerAppListCommand.ContainerAppListCommandResult))] | ||
| [JsonSerializable(typeof(Models.ContainerAppInfo))] | ||
| [JsonSourceGenerationOptions( | ||
| PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, | ||
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] | ||
| internal sealed partial class ContainerAppsJsonContext : JsonSerializerContext | ||
| { | ||
| } |
34 changes: 34 additions & 0 deletions
34
tools/Azure.Mcp.Tools.ContainerApps/src/ContainerAppsSetup.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Mcp.Tools.ContainerApps.Commands.ContainerApp; | ||
| using Azure.Mcp.Tools.ContainerApps.Services; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Mcp.Core.Areas; | ||
| using Microsoft.Mcp.Core.Commands; | ||
|
|
||
| namespace Azure.Mcp.Tools.ContainerApps; | ||
|
|
||
| public class ContainerAppsSetup : IAreaSetup | ||
| { | ||
| public string Name => "containerapps"; | ||
|
|
||
| public string Title => "Azure Container Apps Management"; | ||
|
|
||
| public void ConfigureServices(IServiceCollection services) | ||
| { | ||
| services.AddSingleton<IContainerAppsService, ContainerAppsService>(); | ||
|
|
||
| services.AddSingleton<ContainerAppListCommand>(); | ||
| } | ||
|
|
||
| public CommandGroup RegisterCommands(IServiceProvider serviceProvider) | ||
| { | ||
| var containerapps = new CommandGroup(Name, "Azure Container Apps operations - Commands for managing Azure Container Apps resources. Includes operations for listing container apps and managing container app configurations.", Title); | ||
|
|
||
| var containerAppList = serviceProvider.GetRequiredService<ContainerAppListCommand>(); | ||
| containerapps.AddCommand(containerAppList.Name, containerAppList); | ||
|
|
||
| return containerapps; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| global using System.CommandLine; | ||
| global using Azure.Mcp.Core.Commands; | ||
| global using Azure.Mcp.Core.Options; |
13 changes: 13 additions & 0 deletions
13
tools/Azure.Mcp.Tools.ContainerApps/src/Models/ContainerAppInfo.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Azure.Mcp.Tools.ContainerApps.Models; | ||
|
|
||
| public sealed record ContainerAppInfo( | ||
| [property: JsonPropertyName("name")] string Name, | ||
| [property: JsonPropertyName("location")] string? Location, | ||
| [property: JsonPropertyName("resourceGroup")] string? ResourceGroup, | ||
| [property: JsonPropertyName("managedEnvironmentId")] string? ManagedEnvironmentId, | ||
| [property: JsonPropertyName("provisioningState")] string? ProvisioningState); |
8 changes: 8 additions & 0 deletions
8
tools/Azure.Mcp.Tools.ContainerApps/src/Options/ContainerApp/ContainerAppListOptions.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Azure.Mcp.Tools.ContainerApps.Options.ContainerApp; | ||
|
|
||
| public class ContainerAppListOptions : SubscriptionOptions | ||
| { | ||
| } |
59 changes: 59 additions & 0 deletions
59
tools/Azure.Mcp.Tools.ContainerApps/src/Services/ContainerAppsService.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json; | ||
| using Azure.Mcp.Core.Services.Azure; | ||
| using Azure.Mcp.Core.Services.Azure.Subscription; | ||
| using Azure.Mcp.Core.Services.Azure.Tenant; | ||
| using Azure.Mcp.Tools.ContainerApps.Models; | ||
|
|
||
| namespace Azure.Mcp.Tools.ContainerApps.Services; | ||
|
|
||
| public sealed class ContainerAppsService(ISubscriptionService subscriptionService, ITenantService tenantService) | ||
| : BaseAzureResourceService(subscriptionService, tenantService), IContainerAppsService | ||
| { | ||
| public async Task<ResourceQueryResults<ContainerAppInfo>> ListContainerApps( | ||
| string subscription, | ||
| string? resourceGroup = null, | ||
| string? tenant = null, | ||
| RetryPolicyOptions? retryPolicy = null, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| ValidateRequiredParameters((nameof(subscription), subscription)); | ||
|
|
||
| try | ||
| { | ||
| var containerApps = await ExecuteResourceQueryAsync( | ||
| "Microsoft.App/containerApps", | ||
| resourceGroup, | ||
| subscription, | ||
| retryPolicy, | ||
| ConvertToContainerAppInfoModel, | ||
| cancellationToken: cancellationToken); | ||
|
|
||
| return containerApps; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| throw new Exception($"Error retrieving container apps: {ex.Message}", ex); | ||
| } | ||
ArthurMa1978 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private static ContainerAppInfo ConvertToContainerAppInfoModel(JsonElement item) | ||
| { | ||
| var name = item.TryGetProperty("name", out var nameElement) ? nameElement.GetString() ?? string.Empty : string.Empty; | ||
| var location = item.TryGetProperty("location", out var locationElement) ? locationElement.GetString() : null; | ||
| var resourceGroup = item.TryGetProperty("resourceGroup", out var rgElement) ? rgElement.GetString() : null; | ||
|
|
||
| string? managedEnvironmentId = null; | ||
| string? provisioningState = null; | ||
|
|
||
| if (item.TryGetProperty("properties", out var properties)) | ||
| { | ||
| managedEnvironmentId = properties.TryGetProperty("managedEnvironmentId", out var envElement) ? envElement.GetString() : null; | ||
| provisioningState = properties.TryGetProperty("provisioningState", out var stateElement) ? stateElement.GetString() : null; | ||
| } | ||
|
|
||
| return new ContainerAppInfo(name, location, resourceGroup, managedEnvironmentId, provisioningState); | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
tools/Azure.Mcp.Tools.ContainerApps/src/Services/IContainerAppsService.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Mcp.Core.Services.Azure; | ||
| using Azure.Mcp.Tools.ContainerApps.Models; | ||
|
|
||
| namespace Azure.Mcp.Tools.ContainerApps.Services; | ||
|
|
||
| public interface IContainerAppsService | ||
| { | ||
| Task<ResourceQueryResults<ContainerAppInfo>> ListContainerApps( | ||
| string subscription, | ||
| string? resourceGroup = null, | ||
| string? tenant = null, | ||
| RetryPolicyOptions? retryPolicy = null, | ||
| CancellationToken cancellationToken = default); | ||
| } |
22 changes: 22 additions & 0 deletions
22
...ts/Azure.Mcp.Tools.ContainerApps.UnitTests/Azure.Mcp.Tools.ContainerApps.UnitTests.csproj
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
| <PackageReference Include="NSubstitute" /> | ||
| <PackageReference Include="NSubstitute.Analyzers.CSharp" /> | ||
| <PackageReference Include="xunit.v3" /> | ||
| <PackageReference Include="xunit.v3.assert" /> | ||
| <PackageReference Include="xunit.runner.visualstudio" /> | ||
| <PackageReference Include="coverlet.collector" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Azure.Mcp.Tools.ContainerApps.csproj" /> | ||
| <ProjectReference Include="$(RepoRoot)core\Azure.Mcp.Core\tests\Azure.Mcp.Tests\Azure.Mcp.Tests.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.