src/Commands/AppConfig/Account/AccountListCommand.cs (47 lines of code) (raw):
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.CommandLine.Parsing;
using AzureMcp.Arguments.AppConfig.Account;
using AzureMcp.Models.AppConfig;
using AzureMcp.Models.Command;
using AzureMcp.Services.Interfaces;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
namespace AzureMcp.Commands.AppConfig.Account;
public sealed class AccountListCommand(ILogger<AccountListCommand> logger) : SubscriptionCommand<AccountListArguments>()
{
private readonly ILogger<AccountListCommand> _logger = logger;
protected override string GetCommandName() => "list";
protected override string GetCommandDescription() =>
"""
List all App Configuration stores in a subscription. This command retrieves and displays all App Configuration
stores available in the specified subscription. Results include store names returned as a JSON array.
""";
[McpServerTool(Destructive = false, ReadOnly = true)]
public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult)
{
var args = BindArguments(parseResult);
try
{
if (!await ProcessArguments(context, args))
{
return context.Response;
}
var appConfigService = context.GetService<IAppConfigService>();
var accounts = await appConfigService.GetAppConfigAccounts(
args.Subscription!,
args.Tenant,
args.RetryPolicy);
context.Response.Results = accounts?.Count > 0 ?
ResponseResult.Create(
new AccountListCommandResult(accounts),
AppConfigJsonContext.Default.AccountListCommandResult) :
null;
}
catch (Exception ex)
{
_logger.LogError(ex, "An exception occurred listing accounts.");
HandleException(context.Response, ex);
}
return context.Response;
}
internal record AccountListCommandResult(List<AppConfigurationAccount> Accounts);
}