Fix SQL subscription name-to-GUID resolution#2861
Merged
Merged
Conversation
Resolve the subscription through ISubscriptionService in GetSqlServerResourceAsync, RenameDatabaseAsync, ListServersAsync, and CreateServerAsync instead of building a SubscriptionResource directly from the raw subscription value, which failed with a cryptic ARM error when a subscription display name was passed instead of a GUID. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Azure SQL tools’ subscription handling so callers can pass either a subscription display name or a GUID, aligning SQL behavior with other toolsets by resolving subscriptions through ISubscriptionService.
Changes:
- Updated
SqlServiceto resolve subscriptions viaISubscriptionService.GetSubscription(...)in the affected SQL operations (server show/list/create and db rename), and to use the resolved subscription ID when constructing SQL DB resource identifiers for rename. - Added unit tests intended to validate that each affected method routes subscription resolution through
ISubscriptionServicewhen given a display name. - Added an Azure MCP Server changelog entry describing the bug fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tools/Azure.Mcp.Tools.Sql/tests/Azure.Mcp.Tools.Sql.Tests/Services/SqlServiceTests.cs | Adds unit tests to assert the service resolves subscriptions via ISubscriptionService. |
| tools/Azure.Mcp.Tools.Sql/src/Services/SqlService.cs | Switches SQL operations from direct subscription identifier construction to subscription resolution through ISubscriptionService. |
| servers/Azure.Mcp.Server/changelog-entries/vcolin7-sql-subscription-resolution.yaml | Documents the SQL subscription name-to-GUID resolution fix in the server changelog entry format. |
The subscription name-to-GUID fix (#449/#453) adds a GET /subscriptions/{id} ARM call via ISubscriptionService before navigating to the SQL server. The prior recordings lacked that interaction, causing playback mismatches for the four tests that route through GetSqlServerResourceAsync. Re-recorded them and updated the assets tag. Re-recorded: ListSqlServerEntraAdmins, ListSqlServerFirewallRules, CreateFirewallRule, DeleteFirewallRule. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
vcolin7
added a commit
that referenced
this pull request
Jun 16, 2026
…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>
alzimmermsft
approved these changes
Jun 22, 2026
vcolin7
added a commit
that referenced
this pull request
Jun 22, 2026
* Fix SQL list databases and elastic pools to filter by server (#448, #452) 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> * Switch SQL list databases/elastic pools to ARM SDK (#448, #452) 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> * Re-record SQL list databases/elastic pools tests after ARM SDK switch (#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> * Resolve subscription name or ID for SQL list databases and elastic pools (#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> * Scope SQL get database to the requested server (#451) GetDatabaseAsync used a Resource Graph query filtered only by database name, so it could return a database from a different server sharing the same name in the resource group. It now navigates the ARM resource hierarchy (subscription -> resource group -> server -> database) so the lookup is server-scoped by construction, consistent with ListDatabasesAsync and GetElasticPoolsAsync. Subscription name-or-ID resolution is preserved via ResolveSubscriptionIdAsync. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Re-record SQL db get test after server-scoped ARM SDK switch (#451) GetDatabaseAsync now issues ARM GETs (resource group -> server -> database) instead of a Resource Graph query, so the Should_ShowDatabase_Successfully recording was regenerated. Updates the assets tag to the newly published recording. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # tools/Azure.Mcp.Tools.Sql/tests/Azure.Mcp.Tools.Sql.Tests/Services/SqlServiceTests.cs # tools/Azure.Mcp.Tools.Sql/tests/Azure.Mcp.Tools.Sql.Tests/assets.json
The merge routed firewall, Entra admin, database, and elastic pool
operations through GetSqlServerResourceAsync, which now resolves the
subscription via GetSubscription. Existing recordings lacked the new
GET /subscriptions/{id} interaction, so 7 recorded tests failed in
playback. Re-recorded the affected tests against live resources and
published a combined assets tag (Azure.Mcp.Tools.Sql.Tests_63ef836a47).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
alzimmermsft
approved these changes
Jun 23, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Several Azure SQL operations failed with a cryptic ARM error when a user passed a subscription display name instead of a subscription GUID. The root cause: four methods in
SqlServicebuilt aSubscriptionResourcedirectly from the rawsubscriptionargument viaSubscriptionResource.CreateResourceIdentifier(subscription), which only accepts a GUID.This PR resolves the subscription through the injected
ISubscriptionService(the same pattern the Storage and Cosmos toolsets use), so both subscription IDs and names work consistently.Affected methods:
GetSqlServerResourceAsyncListServersAsyncCreateServerAsyncRenameDatabaseAsyncAdded
SqlServiceTestswith four unit tests proving each method resolves throughISubscriptionServicewhen given a display name.GitHub issue number?
Fixes #449
Fixes #453
Pre-merge Checklist
Invoking Livetests
Copilot submitted PRs are not trustworthy by default. Users with
writeaccess 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.