Skip to content

Add the ability to disable caching when starting the server#2330

Open
alzimmermsft wants to merge 5 commits intomicrosoft:mainfrom
alzimmermsft:AddDisableCacheConfiguration
Open

Add the ability to disable caching when starting the server#2330
alzimmermsft wants to merge 5 commits intomicrosoft:mainfrom
alzimmermsft:AddDisableCacheConfiguration

Conversation

@alzimmermsft
Copy link
Copy Markdown
Contributor

What does this PR do?

Adds the option --disable-caching for starting the MCP server to disable caching of resources that can be cached, requiring repeated requests to fetch resources each time. And update starting the MCP server in testing to disable caching so all tests run all required requests to perform complete validation.

Also, slight change to where ICacheService is injected to always happen in ServiceStartCommand, removing it from being added in Program.cs (which should help improve CLI command performance as it is one less service that needs to be setup, and caching is pointless in CLI as everything it built and torn down for the one operation).

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
    • Created a changelog entry if the change falls among the following: new feature, bug fix, UI/UX update, breaking change, or updated dependencies. Follow the changelog entry guide
  • 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 running the script ./eng/scripts/Process-PackageReadMe.ps1. See Package README
    • 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 tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For renamed tools, follow the Tool Rename Checklist and tag the PR with the breaking-change label
    • 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 command list in servers/Azure.Mcp.Server/docs/azmcp-commands.md
    • Ran ./eng/scripts/Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • 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

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

Adds a new server-start flag to disable resource caching and wires it through server host creation, with associated docs/test harness updates. It also relocates cache service registration for server hosts into ServiceStartCommand.

Changes:

  • Add --disable-caching to server start options and bind it into ServiceStartOptions.
  • Introduce NoopCacheService and conditionally register it (vs. existing cache services) when starting STDIO/HTTP hosts.
  • Update Azure command docs and test harness defaults to start servers with caching disabled.

Reviewed changes

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

Show a summary per file
File Description
servers/Template.Mcp.Server/src/Program.cs Removes CLI-container cache registration (now expected to be handled during server start).
servers/Fabric.Mcp.Server/src/Program.cs Removes CLI-container cache registration and updates warning comment.
servers/Fabric.Mcp.Server/changelog-entries/1775162068769.yaml Adds changelog entry for --disable-caching.
servers/Azure.Mcp.Server/src/Program.cs Removes CLI-container cache registration and updates warning comment.
servers/Azure.Mcp.Server/docs/azmcp-commands.md Documents --disable-caching under azmcp server start.
servers/Azure.Mcp.Server/changelog-entries/1775162061580.yaml Adds changelog entry for --disable-caching.
core/Microsoft.Mcp.Core/tests/Microsoft.Mcp.Tests/Client/LiveServerFixture.cs Minor modernization of collection initialization.
core/Microsoft.Mcp.Core/tests/Microsoft.Mcp.Tests/Client/Helpers/McpTestUtilities.cs Simplifies Process/ProcessStartInfo references.
core/Microsoft.Mcp.Core/tests/Microsoft.Mcp.Tests/Client/CommandTestsBase.cs Starts test servers with --disable-caching.
core/Microsoft.Mcp.Core/src/Services/Caching/NoopCacheService.cs Adds a no-op ICacheService implementation.
core/Microsoft.Mcp.Core/src/Services/Caching/CachingServiceCollectionExtensions.cs Adds AddNoopCacheService DI registration helper.
core/Microsoft.Mcp.Core/src/Areas/Server/Options/ServiceStartOptions.cs Adds DisableCaching option to server start options model.
core/Microsoft.Mcp.Core/src/Areas/Server/Options/ServiceOptionDefinitions.cs Defines the new --disable-caching command-line option.
core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs Registers/binds the new option and conditionally configures caching for STDIO/HTTP hosts.

Copy link
Copy Markdown
Contributor

@jongio jongio left a comment

Choose a reason for hiding this comment

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

Noop logic in extension methods (per vukelich's feedback) is a good approach. DI flow is correct - TryAdd in the CLI container lets the server host registration take precedence.

Issues to address:

  • CachingServiceCollectionExtensions.cs:31 - disabled param needs a default value to avoid breaking existing callers
  • ServiceStartOptions.cs:108 - cachingDisabled should be disableCaching to match other boolean options
  • Azure.Mcp.Server/Program.cs:235 - comment dropped mention of ICacheService but it's still registered there

Note: 4 CI build configs are failing.

@alzimmermsft alzimmermsft requested a review from xiangyan99 as a code owner April 3, 2026 13:57
Copy link
Copy Markdown
Contributor

@jongio jongio left a comment

Choose a reason for hiding this comment

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

Looks good overall - DI wiring is correct and the feature works as intended. A few things to address:

Tests are incomplete:

  • BindOptions_WithDefaults (ServiceStartCommandTests.cs:284) checks every other option's default but skips DisableCaching. Add Assert.False(options.DisableCaching).
  • CreateParseResultWithAllOptions (ServiceStartCommandTests.cs:884) doesn't pass --disable-caching, and BindOptions_WithAllOptions doesn't assert it. Full round-trip binding isn't tested for this option.
  • Consider adding DisableCachingOption_DefaultsToFalse to match the pattern every other boolean option follows.
  • Only option parsing is tested - nothing validates that the DI container actually resolves NoopCacheService when the flag is set.

See inline comments for the other items (sealed, DI ordering comment, named arg).

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.

5 participants