Skip to content

Fix SQL list databases and elastic pools to scope by server#2865

Open
vcolin7 wants to merge 4 commits into
mainfrom
vcolin7/sql-servername-filter
Open

Fix SQL list databases and elastic pools to scope by server#2865
vcolin7 wants to merge 4 commits into
mainfrom
vcolin7/sql-servername-filter

Conversation

@vcolin7

@vcolin7 vcolin7 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

The SQL db get (list databases) and elastic-pool list tools incorrectly ignored the server parameter and returned every database / elastic pool in a given resource group, not just those on the requested server.

Rather than patch the ARG queries with a server predicate, this PR switches both ListDatabasesAsync and GetElasticPoolsAsync to the typed ARM SDK server-scoped collection pattern already used by the sibling read methods (GetEntraAdministratorsAsync, ListFirewallRulesAsync, ListServersAsync). Server scoping is now part of the request URL path instead of a KQL filter. This keeps the SQL service consistent with the rest of the toolset.

Key changes

  • SqlService.cs: rewrote both methods to resolve the server resource and enumerate its GetSqlDatabases() / GetElasticPools() collections; removed ARG-only helpers and the System.Text.Json shadow-model conversion.
  • ISqlService.cs: return types are now List<SqlDatabase> / List<SqlElasticPool> (dropped ResourceQueryResults).
  • DatabaseGetCommand.cs / ElasticPoolListCommand.cs: consume List<T> and drop the AreResultsTruncated field, matching FirewallRuleListResult.
  • Removed now-orphaned JSON shadow models and their SqlJsonContext registrations.
  • Updated command unit tests to the new List<T> mocks and re-recorded the affected SqlCommandTests integration tests (assets.json bumped to Azure.Mcp.Tools.Sql.Tests_50222315f7).

GitHub issue number?

Fixes #448
Fixes #452

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages
    • Added comprehensive tests for new/modified functionality
    • Created a changelog entry
  • For MCP tool changes:
    • One tool per PR: Scoped to the SQL list-databases / list-elastic-pools behavior fix
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation — N/A (no description or surface change)
    • Validate README.md changes running the script ./eng/scripts/Process-PackageReadMe.ps1 — N/A
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator — N/A (descriptions unchanged)
    • For tools with new names, update consolidated-tools.json — N/A
    • For renamed tools, follow the Tool Rename Checklist — N/A
    • For new tools, add URL to documentation — N/A
  • Extra steps for Azure MCP Server tool changes:
    • Updated command list in azmcp-commands.md — N/A (no command/option changes)
    • Ran ./eng/scripts/Update-AzCommandsMetadata.ps1 — N/A
    • Updated test prompts in e2eTestPrompts.md — N/A
    • 👉 For Community PRs — N/A

Invoking Livetests

Copilot submitted PRs are not trustworthy by default. Users with write access to the repo need to validate the contents of this PR before leaving a comment with the text /azp run mcp - pullrequest - live. This will trigger the necessary livetest workflows to complete required validation.

vcolin7 and others added 3 commits June 8, 2026 15:28
)

ListDatabasesAsync and GetElasticPoolsAsync ignored serverName and returned all resources in the resource group. Scope the Azure Resource Graph query to the requested server via an id-contains additionalFilter, extracted into a testable BuildServerResourceFilter helper, and add unit tests covering the filter and KQL escaping.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Align ListDatabasesAsync and GetElasticPoolsAsync with the sibling list methods (GetEntraAdministratorsAsync, ListFirewallRulesAsync, ListServersAsync) by using the server-scoped ARM SDK collections instead of an Azure Resource Graph 'id contains' filter. Server scoping is now structural (the server is part of the request path) rather than a KQL predicate, and the SDK auto-pages the full set so the ResourceQueryResults truncation model is no longer needed.

- ISqlService/SqlService: return List<T>; iterate GetSqlDatabases()/GetElasticPools().GetAllAsync(); add SDK-based ConvertToSqlElasticPoolModel(ElasticPoolResource).

- Commands: consume List<T>; drop AreResultsTruncated from result records (matches FirewallRuleListResult).

- Remove now-orphaned elastic-pool JSON shadow models and their serialization registrations; drop obsolete BuildServerResourceFilter helper and its unit test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…#448, #452)

The switch from Azure Resource Graph to the typed ARM SDK changed the outgoing REST requests for ListDatabasesAsync and GetElasticPoolsAsync, invalidating the existing SqlCommandTests recordings. Re-recorded the SqlCommandTests session records and updated assets.json to the new tag (Azure.Mcp.Tools.Sql.Tests_50222315f7).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Azure SQL db get (list databases) and elastic-pool list returning resources across all servers in a resource group by switching the underlying implementation from Azure Resource Graph (resource-group scoped) to server-scoped ARM SDK collections.

Changes:

  • Reworked SqlService.ListDatabasesAsync and SqlService.GetElasticPoolsAsync to enumerate server-scoped ARM collections (GetSqlDatabases() / GetElasticPools()), returning List<T> instead of ResourceQueryResults<T>.
  • Updated SQL commands and unit tests to consume the new List<T> return types and removed the AreResultsTruncated output field.
  • Removed now-unused JSON shadow models and corresponding SqlJsonContext registrations; updated SQL test recordings tag (assets.json) and added a changelog entry.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.Sql/src/Services/SqlService.cs Switched database + elastic pool listing to server-scoped ARM SDK enumeration and updated elastic pool conversion to typed SDK models.
tools/Azure.Mcp.Tools.Sql/src/Services/ISqlService.cs Updated method return types to List<SqlDatabase> / List<SqlElasticPool>.
tools/Azure.Mcp.Tools.Sql/src/Commands/Database/DatabaseGetCommand.cs Updated response wrapper to accept List<SqlDatabase> and removed truncation field.
tools/Azure.Mcp.Tools.Sql/src/Commands/ElasticPool/ElasticPoolListCommand.cs Updated response wrapper to accept List<SqlElasticPool> and removed truncation field.
tools/Azure.Mcp.Tools.Sql/src/Commands/SqlJsonContext.cs Removed source-gen registrations for deleted elastic pool JSON shadow models.
tools/Azure.Mcp.Tools.Sql/src/Services/Models/SqlElasticPoolData.cs Deleted unused ARG JSON shadow model.
tools/Azure.Mcp.Tools.Sql/src/Services/Models/SqlElasticPoolProperties.cs Deleted unused ARG JSON shadow model.
tools/Azure.Mcp.Tools.Sql/src/Services/Models/SqlElasticPoolPerDatabaseSettings.cs Deleted unused ARG JSON shadow model.
tools/Azure.Mcp.Tools.Sql/tests/Azure.Mcp.Tools.Sql.Tests/Database/DatabaseGetCommandTests.cs Updated mocks to return List<SqlDatabase> instead of ResourceQueryResults.
tools/Azure.Mcp.Tools.Sql/tests/Azure.Mcp.Tools.Sql.Tests/ElasticPool/ElasticPoolListCommandTests.cs Updated mocks to return List<SqlElasticPool> instead of ResourceQueryResults.
tools/Azure.Mcp.Tools.Sql/tests/Azure.Mcp.Tools.Sql.Tests/assets.json Updated recordings tag to Azure.Mcp.Tools.Sql.Tests_50222315f7.
servers/Azure.Mcp.Server/changelog-entries/copilot-fix-sql-server-filter.yaml Added changelog entry documenting the server-scoping fix.

Comment thread tools/Azure.Mcp.Tools.Sql/src/Services/SqlService.cs
Comment thread tools/Azure.Mcp.Tools.Sql/src/Services/SqlService.cs
@vcolin7 vcolin7 changed the title Fix SQL list databases/elastic pools to scope by server (#448, #452) Fix SQL list databases and elastic pools to scope by server Jun 12, 2026
@vcolin7 vcolin7 requested review from alzimmermsft and g2vinay June 12, 2026 02:57
…ols (#448, #452)

The ARM SDK refactor of ListDatabasesAsync and GetElasticPoolsAsync routed the subscription through SubscriptionResource.CreateResourceIdentifier, which only accepts a subscription GUID. This regressed the prior Resource Graph behavior where a subscription name also worked, as flagged by Copilot review on PR #2865.

Scope the fix narrowly to just these two list methods by resolving the subscription via ISubscriptionService before navigating the ARM hierarchy. The shared GetSqlServerResourceAsync helper and the server/firewall/entra-admin/create/rename paths are intentionally left unchanged to avoid overlapping with PR #2861. The new ResolveSubscriptionIdAsync helper skips the extra ARM request when the value is already a subscription ID, so existing recordings remain valid.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vcolin7 vcolin7 force-pushed the vcolin7/sql-servername-filter branch from aee3d02 to 754015e Compare June 16, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants