Skip to content

Read default subscription from Azure CLI profile for all subscription-scoped commands#1974

Open
Copilot wants to merge 8 commits intomainfrom
copilot/fix-issue-1079
Open

Read default subscription from Azure CLI profile for all subscription-scoped commands#1974
Copilot wants to merge 8 commits intomainfrom
copilot/fix-issue-1079

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

  • Analyze all 5 PR review comments
  • Comment 1: Short-circuit HasSubscriptionAvailable when --subscription option is present to avoid unnecessary file IO
  • Comment 2: Only call GetDefaultSubscription() in GetSubscription when value is null/empty/placeholder (lazy evaluation)
  • Comment 3: Guard GetAzureProfilePath() against empty user profile directory to avoid relative path reads
  • Comment 4: Update SubscriptionListCommand.Description to mention AZURE_SUBSCRIPTION_ID env var fallback
  • Comment 5: Breaking change acknowledged — original main already returns isDefault in description; SubscriptionInfo model docs mention both sources
  • Build and test changes (24 tests pass)
  • Run code review

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 10, 2026 00:01
…cription to guide AI agent behavior

The subscription_list tool now:
- Returns a SubscriptionInfo model with isDefault field indicating the default subscription
  (based on AZURE_SUBSCRIPTION_ID environment variable)
- Sorts subscriptions so the default appears first in the list
- Updated description instructs AI agents to prefer the default subscription or ask the
  user when no default is set and multiple subscriptions exist

Fixes #1079

Co-authored-by: ArthurMa1978 <20514459+ArthurMa1978@users.noreply.github.com>
Co-authored-by: ArthurMa1978 <20514459+ArthurMa1978@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with mcp repository according to issue 1079 Add isDefault field to subscription_list response and guide AI subscription selection Mar 10, 2026
Copilot AI and others added 2 commits March 10, 2026 07:46
…cription detection

Read the default subscription from ~/.azure/azureProfile.json (set via 'az account set')
as the primary source. Fall back to AZURE_SUBSCRIPTION_ID environment variable only if
the profile is unavailable.

- Add GetDefaultSubscriptionId() to ISubscriptionService interface
- Implement ReadDefaultSubscriptionFromAzureProfile in SubscriptionService
- Update SubscriptionListCommand to use service method instead of env var directly
- Update tool description to reference 'az account set'
- Add 6 new profile-reading unit tests
- Update existing tests to use mocked GetDefaultSubscriptionId()

Co-authored-by: ArthurMa1978 <20514459+ArthurMa1978@users.noreply.github.com>
Co-authored-by: ArthurMa1978 <20514459+ArthurMa1978@users.noreply.github.com>
Copilot AI changed the title Add isDefault field to subscription_list response and guide AI subscription selection Read default subscription from Azure CLI profile instead of AZURE_SUBSCRIPTION_ID Mar 10, 2026
Copilot AI and others added 2 commits March 10, 2026 10:15
… into CommandHelper for all subscription-scoped commands

- Create AzureCliProfileHelper in Microsoft.Mcp.Core for reading default subscription from ~/.azure/azureProfile.json
- Update CommandHelper.GetSubscription() and HasSubscriptionAvailable() to use Azure CLI profile as primary fallback (before AZURE_SUBSCRIPTION_ID env var)
- Update SubscriptionService.GetDefaultSubscriptionId() to delegate to shared logic
- Update SubscriptionCommand comments to reflect new behavior
- Migrate SubscriptionServiceProfileTests to test AzureCliProfileHelper directly

Co-authored-by: ArthurMa1978 <20514459+ArthurMa1978@users.noreply.github.com>
Co-authored-by: ArthurMa1978 <20514459+ArthurMa1978@users.noreply.github.com>
Copilot AI changed the title Read default subscription from Azure CLI profile instead of AZURE_SUBSCRIPTION_ID Read default subscription from Azure CLI profile for all subscription-scoped commands Mar 10, 2026
@ArthurMa1978 ArthurMa1978 marked this pull request as ready for review March 11, 2026 03:28
@ArthurMa1978 ArthurMa1978 requested review from a team as code owners March 11, 2026 03:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates subscription resolution across subscription-scoped commands to match Azure CLI behavior by reading the default subscription from ~/.azure/azureProfile.json (set via az account set) before falling back to AZURE_SUBSCRIPTION_ID, and surfaces that default selection in subscription list.

Changes:

  • Added AzureCliProfileHelper and CommandHelper.GetDefaultSubscription() to implement the default-subscription fallback chain.
  • Updated subscription option validation/resolution to use the shared default-subscription logic.
  • Updated subscription list to return an isDefault indicator and prioritize the default subscription in the output.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
servers/Azure.Mcp.Server/docs/azmcp-commands.md Updates CLI docs for subscription list to mention isDefault.
core/Microsoft.Mcp.Core/src/Helpers/CommandHelper.cs Adds GetDefaultSubscription() and routes subscription resolution/validation through it.
core/Microsoft.Mcp.Core/src/Helpers/AzureCliProfileHelper.cs New helper to parse Azure CLI profile JSON for the default subscription.
core/Azure.Mcp.Core/src/Services/Azure/Subscription/ISubscriptionService.cs Adds GetDefaultSubscriptionId() to expose shared default-subscription resolution.
core/Azure.Mcp.Core/src/Services/Azure/Subscription/SubscriptionService.cs Implements GetDefaultSubscriptionId() via CommandHelper.
core/Azure.Mcp.Core/src/Commands/Subscription/SubscriptionCommand.cs Updates validation comments to include the new fallback sources.
core/Azure.Mcp.Core/src/Areas/Subscription/Models/SubscriptionInfo.cs Introduces a model that includes isDefault for subscription list output.
core/Azure.Mcp.Core/src/Areas/Subscription/Commands/SubscriptionListCommand.cs Maps subscriptions to SubscriptionInfo, marks/sorts the default subscription, and updates description.
core/Azure.Mcp.Core/src/Areas/Subscription/Commands/SubscriptionJsonContext.cs Adds source-gen serialization metadata for the new output model.
core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Areas/Subscription/SubscriptionListCommandTests.cs Extends unit tests to cover default subscription marking/sorting and isDefault output.
core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Areas/Subscription/AzureCliProfileHelperTests.cs Adds unit tests for parsing the default subscription from Azure CLI profile JSON.

…e, update description

- Short-circuit HasSubscriptionAvailable when --subscription option is present (avoid unnecessary file IO)
- Only call GetDefaultSubscription() in GetSubscription when value is null/empty/placeholder (lazy evaluation)
- Guard GetAzureProfilePath() against empty user profile to avoid relative path reads
- Update SubscriptionListCommand description to mention AZURE_SUBSCRIPTION_ID env var fallback

Co-authored-by: ArthurMa1978 <20514459+ArthurMa1978@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants