Skip to content

Improve Authentication Integration and Experience in MCP Server.#56

Merged
g2vinay merged 10 commits intomicrosoft:mainfrom
g2vinay:add-targeted-credential-selection
Sep 18, 2025
Merged

Improve Authentication Integration and Experience in MCP Server.#56
g2vinay merged 10 commits intomicrosoft:mainfrom
g2vinay:add-targeted-credential-selection

Conversation

@g2vinay
Copy link
Copy Markdown
Contributor

@g2vinay g2vinay commented Aug 26, 2025

Replaces rigid DefaultAzureCredential with flexible credential targeting via the new AZURE_TOKEN_CREDENTIALS environment variable.

Key Changes

New Environment Variable: AZURE_TOKEN_CREDENTIALS

  • "dev" - Development credentials (VS → VSCode → CLI → PowerShell → AzD)
  • "prod" - Production credentials (Environment → WorkloadIdentity → ManagedIdentity)
  • "AzureCliCredential" - Target specific credential
  • Empty/unset - Full credential chain (default)

Smart VS Code Integration (Retains this logic with the refactor).

  • Auto-detects VS Code context (VSCODE_PID)
  • Prioritizes VS Code credential when in VS Code environment
  • Respects explicit AZURE_TOKEN_CREDENTIALS over auto-detection

Robust Error Handling

  • All credentials wrapped with SafeTokenCredential
  • Converts exceptions to CredentialUnavailableException for proper chaining as DAC is no longer used.
  • Better error messages with credential names

Breaking Changes

  • Removed: AZURE_MCP_INCLUDE_PRODUCTION_CREDENTIALS
  • Migration: Use AZURE_TOKEN_CREDENTIALS="prod" instead

@joshfree joshfree added the Do Not Merge Do Not Merge / WIP PRs label Sep 10, 2025
@joshfree
Copy link
Copy Markdown
Member

Labeling as Do Not Merge to make it obvious this doesn't require a code review yet.

@g2vinay g2vinay changed the title Add support for targeted credential selection Improve Authentication Integration and Experience in MCP Server. Sep 16, 2025
@g2vinay g2vinay removed the Do Not Merge Do Not Merge / WIP PRs label Sep 16, 2025
@g2vinay g2vinay marked this pull request as ready for review September 16, 2025 17:15
@g2vinay g2vinay requested a review from a team as a code owner September 16, 2025 17:15
Copy link
Copy Markdown
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

This PR improves Azure authentication by replacing the rigid DefaultAzureCredential with a flexible credential targeting system via the new AZURE_TOKEN_CREDENTIALS environment variable, while maintaining smart VS Code integration and adding robust error handling.

  • Introduces AZURE_TOKEN_CREDENTIALS environment variable for targeted credential selection with options for development ("dev"), production ("prod"), or specific credential types
  • Replaces DefaultAzureCredential with explicit credential chain construction for better control and transparency
  • Adds SafeTokenCredential wrapper to ensure proper exception handling and credential chaining behavior

Reviewed Changes

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

File Description
servers/Azure.Mcp.Server/TROUBLESHOOTING.md Documents the new AZURE_TOKEN_CREDENTIALS environment variable usage and available credential options
servers/Azure.Mcp.Server/CHANGELOG.md Records the authentication enhancement features and removal of deprecated environment variable
core/Azure.Mcp.Core/src/Services/Azure/Authentication/CustomChainedCredential.cs Refactors authentication logic to use explicit credential chains with the new environment variable and adds SafeTokenCredential wrapper

Comment thread servers/Azure.Mcp.Server/TROUBLESHOOTING.md Outdated
@joshfree joshfree added the tools-Core AZMCP Core functionality that all other tools build on top of label Sep 16, 2025
Comment thread core/Azure.Mcp.Core/src/Services/Azure/Authentication/CustomChainedCredential.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Azure/Authentication/CustomChainedCredential.cs Outdated
Comment thread servers/Azure.Mcp.Server/CHANGELOG.md
Comment thread servers/Azure.Mcp.Server/CHANGELOG.md Outdated
@joshfree joshfree added this to the 2025-09 milestone Sep 16, 2025
@joshfree joshfree moved this from Untriaged to In Progress in Azure MCP Server Sep 16, 2025
@joshfree joshfree added the server-Azure.Mcp Azure.Mcp.Server label Sep 17, 2025
@g2vinay g2vinay enabled auto-merge (squash) September 18, 2025 17:56
@g2vinay g2vinay merged commit 1f917c0 into microsoft:main Sep 18, 2025
26 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Azure MCP Server Sep 18, 2025
colbytimm pushed a commit to colbytimm/microsoft-mcp that referenced this pull request Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server-Azure.Mcp Azure.Mcp.Server tools-Core AZMCP Core functionality that all other tools build on top of

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants