-
Notifications
You must be signed in to change notification settings - Fork 434
Expand file tree
/
Copy pathServerConfigGetCommand.cs
More file actions
61 lines (49 loc) · 2.13 KB
/
ServerConfigGetCommand.cs
File metadata and controls
61 lines (49 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Azure.Mcp.Tools.Postgres.Options.Server;
using Azure.Mcp.Tools.Postgres.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Mcp.Core.Commands;
using Microsoft.Mcp.Core.Models.Command;
namespace Azure.Mcp.Tools.Postgres.Commands.Server;
public sealed class ServerConfigGetCommand(IPostgresService postgresService, ILogger<ServerConfigGetCommand> logger) : BaseServerCommand<ServerConfigGetOptions>(logger)
{
private readonly IPostgresService _postgresService = postgresService;
private const string CommandTitle = "Get PostgreSQL Server Configuration";
public override string Id => "049a0d10-0a6e-4278-a0a3-15ce6b2e5ee1";
public override string Name => "get";
public override string Description =>
"Retrieve the configuration of a PostgreSQL server.";
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 config = await _postgresService.GetServerConfigAsync(options.Subscription!, options.ResourceGroup!, options.User!, options.Server!, cancellationToken);
context.Response.Results = config?.Length > 0 ?
ResponseResult.Create(new(config), PostgresJsonContext.Default.ServerConfigGetCommandResult) :
null;
}
catch (Exception ex)
{
_logger.LogError(ex, "An exception occurred retrieving server configuration.");
HandleException(context, ex);
}
return context.Response;
}
internal record ServerConfigGetCommandResult(string Configuration);
}