Read default subscription from Azure CLI profile for all subscription-scoped commands#1974
Open
Read default subscription from Azure CLI profile for all subscription-scoped commands#1974
Conversation
…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
…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
… 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
Contributor
There was a problem hiding this comment.
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
AzureCliProfileHelperandCommandHelper.GetDefaultSubscription()to implement the default-subscription fallback chain. - Updated subscription option validation/resolution to use the shared default-subscription logic.
- Updated
subscription listto return anisDefaultindicator 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. |
core/Azure.Mcp.Core/src/Areas/Subscription/Commands/SubscriptionListCommand.cs
Outdated
Show resolved
Hide resolved
core/Azure.Mcp.Core/src/Areas/Subscription/Commands/SubscriptionListCommand.cs
Show resolved
Hide resolved
…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>
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.
HasSubscriptionAvailablewhen--subscriptionoption is present to avoid unnecessary file IOGetDefaultSubscription()inGetSubscriptionwhen value is null/empty/placeholder (lazy evaluation)GetAzureProfilePath()against empty user profile directory to avoid relative path readsSubscriptionListCommand.Descriptionto mention AZURE_SUBSCRIPTION_ID env var fallbackisDefaultin description; SubscriptionInfo model docs mention both sources🔒 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.