Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changes:
- section: "Breaking Changes"
description: "Removed unused parameters from Sql tools."
28 changes: 0 additions & 28 deletions tools/Azure.Mcp.Tools.Sql/src/Commands/BaseDatabaseCommand.cs

This file was deleted.

This file was deleted.

34 changes: 0 additions & 34 deletions tools/Azure.Mcp.Tools.Sql/src/Commands/BaseSqlCommand.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Licensed under the MIT License.

using System.Net;
using Azure.Mcp.Core.Commands.Subscription;
using Azure.Mcp.Core.Services.Azure.Subscription;
using Azure.Mcp.Tools.Sql.Models;
using Azure.Mcp.Tools.Sql.Options;
using Azure.Mcp.Tools.Sql.Options.Database;
using Azure.Mcp.Tools.Sql.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.Sql.Commands.Database;
Expand All @@ -18,8 +18,8 @@ namespace Azure.Mcp.Tools.Sql.Commands.Database;
Name = "create",
Title = "Create SQL Database",
Description = """
Create a new Azure SQL Database on an existing SQL Server. This command creates a database with configurable
performance tiers, size limits, and other settings. Equivalent to 'az sql db create'.
Create a new Azure SQL Database on an existing SQL Server with configurable performance tiers, size limits,
and other settings. Equivalent to 'az sql db create'.
Returns the newly created database information including configuration details.
""",
Destructive = true,
Expand All @@ -28,53 +28,20 @@ Returns the newly created database information including configuration details.
ReadOnly = false,
Secret = false,
LocalRequired = false)]
public sealed class DatabaseCreateCommand(ISqlService sqlService, ILogger<DatabaseCreateCommand> logger)
: BaseDatabaseCommand<DatabaseCreateOptions>(logger)
public sealed class DatabaseCreateCommand(ISqlService sqlService, ILogger<DatabaseCreateCommand> logger, ISubscriptionResolver subscriptionResolver)
: SubscriptionCommand<DatabaseCreateOptions, DatabaseCreateCommand.DatabaseCreateResult>(subscriptionResolver)
{
private readonly ISqlService _sqlService = sqlService;
private readonly ILogger<DatabaseCreateCommand> _logger = logger;

protected override void RegisterOptions(Command command)
public override async Task<CommandResponse> ExecuteAsync(CommandContext context, DatabaseCreateOptions options, CancellationToken cancellationToken)
{
base.RegisterOptions(command);
command.Options.Add(SqlOptionDefinitions.SkuNameOption);
command.Options.Add(SqlOptionDefinitions.SkuTierOption);
command.Options.Add(SqlOptionDefinitions.SkuCapacityOption);
command.Options.Add(SqlOptionDefinitions.CollationOption);
command.Options.Add(SqlOptionDefinitions.MaxSizeBytesOption);
command.Options.Add(SqlOptionDefinitions.ElasticPoolNameOption);
command.Options.Add(SqlOptionDefinitions.ZoneRedundantOption);
command.Options.Add(SqlOptionDefinitions.ReadScaleOption);
}

protected override DatabaseCreateOptions BindOptions(ParseResult parseResult)
{
var options = base.BindOptions(parseResult);
options.SkuName = parseResult.GetValueOrDefault<string>(SqlOptionDefinitions.SkuNameOption.Name);
options.SkuTier = parseResult.GetValueOrDefault<string>(SqlOptionDefinitions.SkuTierOption.Name);
options.SkuCapacity = parseResult.GetValueOrDefault<int?>(SqlOptionDefinitions.SkuCapacityOption.Name);
options.Collation = parseResult.GetValueOrDefault<string>(SqlOptionDefinitions.CollationOption.Name);
options.MaxSizeBytes = parseResult.GetValueOrDefault<long?>(SqlOptionDefinitions.MaxSizeBytesOption.Name);
options.ElasticPoolName = parseResult.GetValueOrDefault<string>(SqlOptionDefinitions.ElasticPoolNameOption.Name);
options.ZoneRedundant = parseResult.GetValueOrDefault<bool?>(SqlOptionDefinitions.ZoneRedundantOption.Name);
options.ReadScale = parseResult.GetValueOrDefault<string>(SqlOptionDefinitions.ReadScaleOption.Name);
return options;
}

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 database = await _sqlService.CreateDatabaseAsync(
options.Server!,
options.Database!,
options.ResourceGroup!,
options.Server,
options.Database,
options.ResourceGroup,
options.Subscription!,
options.SkuName,
options.SkuTier,
Expand Down Expand Up @@ -114,5 +81,5 @@ public override async Task<CommandResponse> ExecuteAsync(CommandContext context,
_ => base.GetErrorMessage(ex)
};

internal record DatabaseCreateResult(SqlDatabase Database);
public sealed record DatabaseCreateResult(SqlDatabase Database);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the MIT License.

using System.Net;
using Azure.Mcp.Core.Commands.Subscription;
using Azure.Mcp.Core.Services.Azure.Subscription;
using Azure.Mcp.Tools.Sql.Options.Database;
using Azure.Mcp.Tools.Sql.Services;
using Microsoft.Extensions.Logging;
Expand All @@ -14,33 +16,27 @@ namespace Azure.Mcp.Tools.Sql.Commands.Database;
Id = "c4ef0375-0df9-445c-b8ae-2542e9612425",
Name = "delete",
Title = "Delete SQL Database",
Description = "Deletes a database from an Azure SQL Server.This idempotent operation removes the specified database from the server, returning Deleted = false if the database doesn't exist or Deleted = true if successfully removed.",
Description = "Deletes a database from an Azure SQL Server. This idempotent operation removes the specified database from the server, returning Deleted = false if the database doesn't exist or Deleted = true if successfully removed.",
Destructive = true,
Idempotent = true,
OpenWorld = false,
ReadOnly = false,
Secret = false,
LocalRequired = false)]
public sealed class DatabaseDeleteCommand(ISqlService sqlService, ILogger<DatabaseDeleteCommand> logger)
: BaseDatabaseCommand<DatabaseDeleteOptions>(logger)
public sealed class DatabaseDeleteCommand(ISqlService sqlService, ILogger<DatabaseDeleteCommand> logger, ISubscriptionResolver subscriptionResolver)
: SubscriptionCommand<DatabaseDeleteOptions, DatabaseDeleteCommand.DatabaseDeleteResult>(subscriptionResolver)
{
private readonly ISqlService _sqlService = sqlService;
private readonly ILogger<DatabaseDeleteCommand> _logger = logger;

public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult, CancellationToken cancellationToken)
public override async Task<CommandResponse> ExecuteAsync(CommandContext context, DatabaseDeleteOptions options, CancellationToken cancellationToken)
{
if (!Validate(parseResult.CommandResult, context.Response).IsValid)
{
return context.Response;
}

var options = BindOptions(parseResult);

try
{
var deleted = await _sqlService.DeleteDatabaseAsync(
options.Server!,
options.Database!,
options.ResourceGroup!,
options.Server,
options.Database,
options.ResourceGroup,
options.Subscription!,
options.RetryPolicy,
cancellationToken);
Expand Down Expand Up @@ -68,6 +64,6 @@ public override async Task<CommandResponse> ExecuteAsync(CommandContext context,
_ => base.GetErrorMessage(ex)
};

internal record DatabaseDeleteResult(bool Deleted, string DatabaseName);
public sealed record DatabaseDeleteResult(bool Deleted, string DatabaseName);
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// Licensed under the MIT License.

using System.Net;
using Azure.Mcp.Core.Commands.Subscription;
using Azure.Mcp.Core.Services.Azure.Subscription;
using Azure.Mcp.Tools.Sql.Models;
using Azure.Mcp.Tools.Sql.Options;
using Azure.Mcp.Tools.Sql.Options.Database;
using Azure.Mcp.Tools.Sql.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Mcp.Core.Commands;
using Microsoft.Mcp.Core.Extensions;
using Microsoft.Mcp.Core.Models.Command;
using Microsoft.Mcp.Core.Models.Option;

namespace Azure.Mcp.Tools.Sql.Commands.Database;

Expand All @@ -20,52 +19,32 @@ namespace Azure.Mcp.Tools.Sql.Commands.Database;
Title = "Get SQL Database",
Description = """
Show, get, or list Azure SQL databases in a SQL Server. Shows details for a specific Azure SQL database
by name, or lists all Azure SQL databases in the specified SQL Server. Use to show or retrieve Azure SQL
database information. Equivalent to 'az sql db show' (show one Azure SQL database) or 'az sql db list'
(list all Azure SQL databases in a server). Returns database information including configuration details
and current status.
by name, or lists all Azure SQL databases in the specified SQL Server. Equivalent to 'az sql db show'
(show one Azure SQL database) or 'az sql db list' (list all Azure SQL databases in a server).
Returns database information including configuration details and current status.
""",
Destructive = false,
Idempotent = true,
OpenWorld = false,
ReadOnly = true,
Secret = false,
LocalRequired = false)]
public sealed class DatabaseGetCommand(ISqlService sqlService, ILogger<DatabaseGetCommand> logger)
: BaseSqlCommand<DatabaseGetOptions>(logger)
public sealed class DatabaseGetCommand(ISqlService sqlService, ILogger<DatabaseGetCommand> logger, ISubscriptionResolver subscriptionResolver)
: SubscriptionCommand<DatabaseGetOptions, DatabaseGetCommand.DatabaseGetListResult>(subscriptionResolver)
{
private readonly ISqlService _sqlService = sqlService;
private readonly ILogger<DatabaseGetCommand> _logger = logger;

protected override void RegisterOptions(Command command)
public override async Task<CommandResponse> ExecuteAsync(CommandContext context, DatabaseGetOptions options, CancellationToken cancellationToken)
{
base.RegisterOptions(command);
command.Options.Add(SqlOptionDefinitions.Database.AsOptional());
}

protected override DatabaseGetOptions BindOptions(ParseResult parseResult)
{
var options = base.BindOptions(parseResult);
options.Database = parseResult.GetValueOrDefault<string>(SqlOptionDefinitions.Database.Name);
return options;
}

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
{
if (!string.IsNullOrEmpty(options.Database))
{
var database = await _sqlService.GetDatabaseAsync(
options.Server!,
options.Server,
options.Database,
options.ResourceGroup!,
options.ResourceGroup,
options.Subscription!,
options.RetryPolicy,
cancellationToken);
Expand All @@ -77,8 +56,8 @@ public override async Task<CommandResponse> ExecuteAsync(CommandContext context,
else
{
var databases = await _sqlService.ListDatabasesAsync(
options.Server!,
options.ResourceGroup!,
options.Server,
options.ResourceGroup,
options.Subscription!,
options.RetryPolicy,
cancellationToken);
Expand Down Expand Up @@ -109,5 +88,5 @@ public override async Task<CommandResponse> ExecuteAsync(CommandContext context,
_ => base.GetErrorMessage(ex)
};

internal record DatabaseGetListResult(List<SqlDatabase> Databases);
public sealed record DatabaseGetListResult(List<SqlDatabase> Databases);
}
Loading