Skip to content

Fix SQL subscription name-to-GUID resolution#2861

Merged
vcolin7 merged 5 commits into
mainfrom
vcolin7/verbose-tribble
Jun 23, 2026
Merged

Fix SQL subscription name-to-GUID resolution#2861
vcolin7 merged 5 commits into
mainfrom
vcolin7/verbose-tribble

Conversation

@vcolin7

@vcolin7 vcolin7 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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 SqlService built a SubscriptionResource directly from the raw subscription argument via SubscriptionResource.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:

  • GetSqlServerResourceAsync
  • ListServersAsync
  • CreateServerAsync
  • RenameDatabaseAsync

Added SqlServiceTests with four unit tests proving each method resolves through ISubscriptionService when given a display name.

GitHub issue number?

Fixes #449
Fixes #453

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 (bug fix)
  • For MCP tool changes:
    • N/A - no tool was added, renamed, or had its description/signature changed; this is an internal subscription-resolution bug fix.
  • Extra steps for Azure MCP Server tool changes:
    • N/A - command surface and tool metadata are unchanged.

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.

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>

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

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 SqlService to resolve subscriptions via ISubscriptionService.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 ISubscriptionService when 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.

@vcolin7 vcolin7 changed the title Fix SQL subscription name-to-GUID resolution (#449, #453) Fix SQL subscription name-to-GUID resolution Jun 12, 2026
@vcolin7 vcolin7 requested a review from alzimmermsft June 12, 2026 02:03
Comment thread tools/Azure.Mcp.Tools.Sql/src/Services/SqlService.cs
vcolin7 and others added 2 commits June 15, 2026 12:04
…el class in SqlServiceTests

Replaces the SubscriptionResolvedException sentinel type with an
InvalidOperationException carrying a distinctive message, and asserts the
message matches. Addresses review feedback on #449/#453.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
@github-project-automation github-project-automation Bot moved this from Untriaged to In Progress in Azure MCP Server 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>
vcolin7 and others added 2 commits June 22, 2026 16:17
# 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>
@vcolin7 vcolin7 merged commit 8547ed5 into main Jun 23, 2026
15 checks passed
@vcolin7 vcolin7 deleted the vcolin7/verbose-tribble branch June 23, 2026 18:28
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Azure MCP Server Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants