Skip to content

Fix SQL subscription name-to-GUID resolution#2861

Open
vcolin7 wants to merge 3 commits into
mainfrom
vcolin7/verbose-tribble
Open

Fix SQL subscription name-to-GUID resolution#2861
vcolin7 wants to merge 3 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>
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