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 10 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).
core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs
Show resolved
Hide resolved
vukelich
left a comment
There was a problem hiding this comment.
Looks good to me, but I like Jon's review suggestions to update other unit tests. Marking as approved if this needs immediate unblocking, but hit me up if/when the other tests are updated accordingly.
core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs
Show resolved
Hide resolved
core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Areas/Server/ServiceStartCommandTests.cs
Outdated
Show resolved
Hide resolved
jongio
left a comment
There was a problem hiding this comment.
DI wiring and feature implementation look solid. The latest commit consolidating bool option tests into a parameterized theory is a nice cleanup. Two items from my previous review are still missing, plus a new test gap:
Still outstanding:
BindOptions_WithDefaults(ServiceStartCommandTests.cs:274) checks 8 option defaults but skipsDisableCaching. AddAssert.False(options.DisableCaching).-BindOptions_WithAllOptions(ServiceStartCommandTests.cs:219) passes--disable-cachingin args but doesn't assert the bound value. AddAssert.True(options.DisableCaching).
New:
CachingServiceCollectionExtensionsTestscoversAddHttpServiceCacheService_ShouldOverrideExistingCacheServicefor the non-disabled path, but there's no equivalent for the disabled path. Add a test verifyingAddHttpServiceCacheService(disabled: true)also replaces a pre-registeredICacheServicewithNoopCacheService.
Changelog YAML files are missing trailing newlines (minor).
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