Add the ability to disable caching when starting the server#2330
Add the ability to disable caching when starting the server#2330alzimmermsft wants to merge 5 commits intomicrosoft:mainfrom
Conversation
core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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-cachingtoserver startoptions and bind it intoServiceStartOptions. - Introduce
NoopCacheServiceand 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. |
core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs
Show resolved
Hide resolved
jongio
left a comment
There was a problem hiding this comment.
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 -
disabledparam needs a default value to avoid breaking existing callers - ServiceStartOptions.cs:108 -
cachingDisabledshould bedisableCachingto 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.
core/Microsoft.Mcp.Core/src/Services/Caching/CachingServiceCollectionExtensions.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
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 skipsDisableCaching. AddAssert.False(options.DisableCaching).CreateParseResultWithAllOptions(ServiceStartCommandTests.cs:884) doesn't pass--disable-caching, andBindOptions_WithAllOptionsdoesn't assert it. Full round-trip binding isn't tested for this option.- Consider adding
DisableCachingOption_DefaultsToFalseto match the pattern every other boolean option follows. - Only option parsing is tested - nothing validates that the DI container actually resolves
NoopCacheServicewhen the flag is set.
See inline comments for the other items (sealed, DI ordering comment, named arg).
What does this PR do?
Adds the option
--disable-cachingfor 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
ICacheServiceis injected to always happen inServiceStartCommand, removing it from being added inProgram.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
servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationREADME.mdchanges running the script./eng/scripts/Process-PackageReadMe.ps1. See Package READMEToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.jsonbreaking-changelabelservers/Azure.Mcp.Server/docs/azmcp-commands.md./eng/scripts/Update-AzCommandsMetadata.ps1to update tool metadata inazmcp-commands.md(required for CI)servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline