Skip to content

Introduce separate ICacheService implementations for single user CLI vs multi-user web API.#996

Merged
vukelich merged 4 commits intomainfrom
users/vukelich/cacheservice
Nov 3, 2025
Merged

Introduce separate ICacheService implementations for single user CLI vs multi-user web API.#996
vukelich merged 4 commits intomainfrom
users/vukelich/cacheservice

Conversation

@vukelich
Copy link
Copy Markdown
Member

What does this PR do?

[Provide a clear, concise description of the changes]

Update various Azure Data tools to avoid OAuth access token caching directly and instead rely on IAzureTokenCredentialProvider infra to do so.

Remove unsafe instance-level caching in BaseAzureService and Monitor services

Removed stateful fields that cached user-specific credentials and tokens in:

  • BaseAzureService: Removed ArmClient caching and GetCachedTokenAsync helper
  • MonitorHealthModelService: Removed cached dataplane/control plane tokens
  • MonitorService: Removed cached management token

These instance-level caches were not safe for multi-user scenarios where different users access the same service instance with different identities. Now relies on Azure SDK's built-in thread-safe caching in TokenCredential.

GitHub issue number?

[Link to the GitHub issue this PR addresses]

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md and/or servers/Fabric.Mcp.Server/CHANGELOG.md for product changes (features, bug fixes, UI/UX, updated dependencies)
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes using script at eng/scripts/Process-PackageReadMe.ps1. See Package README
    • Updated command list in /servers/Azure.Mcp.Server/docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • Run .\eng\scripts\Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

Comment thread servers/Azure.Mcp.Server/src/Program.cs
Comment thread tools/Azure.Mcp.Tools.MySql/src/Services/MySqlService.cs
conniey
conniey previously approved these changes Oct 29, 2025
@github-project-automation github-project-automation Bot moved this from Untriaged to In Progress in Azure MCP Server Oct 29, 2025
@joshfree joshfree added this to the 2025-11 milestone Oct 29, 2025
anuchandy
anuchandy previously approved these changes Oct 29, 2025
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Azure/BaseAzureService.cs
Comment thread tools/Azure.Mcp.Tools.Monitor/src/Services/MonitorService.cs
srnagar
srnagar previously approved these changes Oct 31, 2025
Comment thread tools/Azure.Mcp.Tools.Marketplace/src/Services/MarketplaceService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Postgres/src/Services/PostgresService.cs
Base automatically changed from feature/2.0beta-remote to main November 3, 2025 01:51
@vukelich vukelich dismissed stale reviews from srnagar, anuchandy, and conniey November 3, 2025 01:51

The base branch was changed.

@vukelich vukelich requested a review from wbreza as a code owner November 3, 2025 01:51
…vs multi-user web API.

Update various Azure Data tools to avoid OAuth access token caching directly and instead rely on IAzureTokenCredentialProvider infra to do so.

Remove unsafe instance-level caching in BaseAzureService and Monitor services

Removed stateful fields that cached user-specific credentials and tokens in:
- BaseAzureService: Removed ArmClient caching and GetCachedTokenAsync helper
- MonitorHealthModelService: Removed cached dataplane/control plane tokens
- MonitorService: Removed cached management token

These instance-level caches were not safe for multi-user scenarios where
different users access the same service instance with different identities.
Now relies on Azure SDK's built-in thread-safe caching in TokenCredential.
Copilot AI review requested due to automatic review settings November 3, 2025 19:43
@vukelich vukelich force-pushed the users/vukelich/cacheservice branch from 53be163 to a00e815 Compare November 3, 2025 19:43
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 refactors token caching logic across multiple Azure service implementations by removing manual token caching and relying on the underlying Azure SDK's built-in token caching mechanism. The changes also introduce distinct cache service implementations for single-user CLI and multi-user web API scenarios.

  • Removes manual token caching (fields and logic) from PostgresService, MySqlService, MonitorService, MonitorHealthModelService, and MarketplaceService
  • Standardizes token acquisition to always use GetCredential() with proper CancellationToken propagation
  • Introduces SingleUserCliCacheService and HttpServiceCacheService as distinct implementations of ICacheService with appropriate DI registration methods
  • Updates parameter naming from tenant to tenantId or tenantIdOrName for clarity in several methods

Reviewed Changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
PostgresService.cs Removed cached token fields and logic, simplified GetEntraIdAccessTokenAsync to use SDK token caching
MySqlService.cs Removed cached token fields, lock object, and caching logic from GetEntraIdAccessTokenAsync
MonitorService.cs Removed GetCachedManagementTokenAsync method and associated caching fields, updated CallActivityLogApiAsync to use direct token acquisition
MonitorHealthModelService.cs Removed token caching fields and GetCachedTokenAsync calls, simplified control plane and dataplane token methods
MonitorCommandTests.cs Updated to use SingleUserCliCacheService instead of CacheService
MarketplaceService.cs Removed GetAccessTokenAsync caching method, renamed method to GetArmAccessTokenAsync, updated documentation from "tenant" to "tenantId"
ProductListCommandTests.cs Updated to use SingleUserCliCacheService
ProductGetCommandTests.cs Updated to use SingleUserCliCacheService
DatadogService.cs Updated parameter name from tenant to tenantIdOrName in CreateArmClientAsync call
AppConfigCommandTests.cs Updated to use SingleUserCliCacheService
Program.cs (Template/Fabric/Azure servers) Updated DI registration to use new AddSingleUserCliCacheService() extension method
CacheServiceTests.cs Updated to use SingleUserCliCacheService
SingleUserCliCacheService.cs Renamed from CacheService, added comprehensive documentation
HttpServiceCacheService.cs New stub implementation for multi-user web API scenarios
CachingServiceCollectionExtensions.cs New file with extension methods for registering cache services
BaseAzureService.cs Removed ArmClient caching, removed GetCachedTokenAsync method, renamed parameter tenant to tenantIdOrName in CreateArmClientAsync
TransportTypes.cs Added Http constant for Streamable HTTP transport
ServiceStartCommand.cs Added AddHttpServiceCacheService() calls for HTTP hosts
launchSettings.json Removed trailing whitespace

Comment thread servers/Azure.Mcp.Server/src/Program.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Azure/BaseAzureService.cs
Comment thread servers/Template.Mcp.Server/src/Program.cs
Copy link
Copy Markdown
Member

@anuchandy anuchandy left a comment

Choose a reason for hiding this comment

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

ty!

Comment thread core/Azure.Mcp.Core/src/Services/Azure/BaseAzureService.cs
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Options/TransportTypes.cs
Comment thread tools/Azure.Mcp.Tools.MySql/src/Services/MySqlService.cs
@anuchandy
Copy link
Copy Markdown
Member

/azp run mcp - pullrequest - live

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@vukelich
Copy link
Copy Markdown
Member Author

vukelich commented Nov 3, 2025

Bypassing merge rule for microsoft/fabric-mcp owner review required. We're making lots of big changes in main, and I'll be working with them to recover after everything settles down.

@vukelich vukelich merged commit 50ff451 into main Nov 3, 2025
29 checks passed
@vukelich vukelich deleted the users/vukelich/cacheservice branch November 3, 2025 22:58
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Azure MCP Server Nov 3, 2025
colbytimm pushed a commit to colbytimm/microsoft-mcp that referenced this pull request Dec 8, 2025
…vs multi-user web API. (microsoft#996)

* Introduce separate ICacheService implementations for single user CLI vs multi-user web API.

Update various Azure Data tools to avoid OAuth access token caching directly and instead rely on IAzureTokenCredentialProvider infra to do so. The cache implementation selected at runtime depends on the `--transport` option, which itself is re-introducing `http` as a choice for remote MCP servers.

Remove unsafe instance-level caching in BaseAzureService and Monitor services

For example, removed stateful fields that cached user-specific credentials and tokens in:
- BaseAzureService: Removed ArmClient caching and GetCachedTokenAsync helper
- MonitorHealthModelService: Removed cached dataplane/control plane tokens
- MonitorService: Removed cached management token

These instance-level caches were not safe for multi-user scenarios where
different users access the same service instance with different identities.
Now relies on Azure SDK's built-in thread-safe caching in TokenCredential.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants