Unify service configuration for ISseEventStreamStore, IMcpTaskStore, and ISessionMigrationHandler#1362
Conversation
src/ModelContextProtocol.AspNetCore/HttpServerTransportOptionsSetup.cs
Outdated
Show resolved
Hide resolved
src/ModelContextProtocol.AspNetCore/HttpMcpServerBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/ModelContextProtocol.AspNetCore/DistributedCacheEventStreamStoreOptionsSetup.cs
Outdated
Show resolved
Hide resolved
src/ModelContextProtocol/Server/DistributedCacheEventStreamStore.cs
Outdated
Show resolved
Hide resolved
mikekistler
left a comment
There was a problem hiding this comment.
I really like the simplicity and consistency of the new API shape.
I can't judge the implementation but from an externals POV this looks good! 👍
d565545
There was a problem hiding this comment.
Pull request overview
This PR unifies the service configuration pattern for ISseEventStreamStore, IMcpTaskStore, and ISessionMigrationHandler to follow a consistent dependency injection approach. Previously, these three services had inconsistent configuration patterns - ISseEventStreamStore was only settable via options callbacks, IMcpTaskStore used reverse-registration into DI, and ISessionMigrationHandler was only resolvable from DI. Now all three follow the same pattern: configurable via an options property with automatic fallback to DI resolution when not explicitly set, with explicit values always taking precedence.
Changes:
- Unified service configuration pattern: all three services now support both explicit options-based configuration and automatic DI resolution via
IConfigureOptions - Refactored
DistributedCacheEventStreamStoreto useIOptions<DistributedCacheEventStreamStoreOptions>pattern with newCacheproperty - Added
WithDistributedCacheEventStreamStore()extension method for simplified configuration
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/ModelContextProtocol/Server/DistributedCacheEventStreamStore.cs |
Changed constructor to accept IOptions<DistributedCacheEventStreamStoreOptions> instead of IDistributedCache directly |
src/ModelContextProtocol/Server/DistributedCacheEventStreamStoreOptions.cs |
Added Cache property to hold the IDistributedCache instance |
src/ModelContextProtocol/McpServerOptionsSetup.cs |
Added IMcpTaskStore parameter and auto-population logic for TaskStore property |
src/ModelContextProtocol/McpServerServiceCollectionExtensions.cs |
Removed reverse-registration of IMcpTaskStore from options |
src/ModelContextProtocol.AspNetCore/HttpServerTransportOptions.cs |
Added SessionMigrationHandler property with documentation |
src/ModelContextProtocol.AspNetCore/HttpServerTransportOptionsSetup.cs |
New: Configures EventStreamStore and SessionMigrationHandler from DI |
src/ModelContextProtocol.AspNetCore/DistributedCacheEventStreamStoreOptionsSetup.cs |
New: Configures Cache property from DI |
src/ModelContextProtocol.AspNetCore/DistributedCacheEventStreamStoreOptionsValidator.cs |
New: Validates that Cache is set with helpful error message |
src/ModelContextProtocol.AspNetCore/HttpMcpServerBuilderExtensions.cs |
Added WithDistributedCacheEventStreamStore() extension method |
src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs |
Updated to use SessionMigrationHandler from options instead of constructor parameter |
tests/ModelContextProtocol.Tests/Server/DistributedCacheEventStreamStoreTests.cs |
Updated all tests to use new constructor signature with CreateStore helper method |
tests/ModelContextProtocol.Tests/Configuration/McpServerOptionsSetupTests.cs |
Added comprehensive tests for TaskStore DI resolution and precedence |
tests/ModelContextProtocol.AspNetCore.Tests/HttpMcpServerBuilderExtensionsTests.cs |
New: Comprehensive tests for EventStreamStore and SessionMigrationHandler configuration patterns |
tests/ModelContextProtocol.AspNetCore.Tests/DistributedCacheResumabilityIntegrationTests.cs |
Updated to use new constructor with Cache property in options |
tests/ModelContextProtocol.ConformanceServer/Program.cs |
Updated to use simplified WithDistributedCacheEventStreamStore() pattern |
Motivation
Three service interfaces had inconsistent configuration patterns:
ISseEventStreamStorecould only be set viaHttpServerTransportOptions.EventStreamStoreinside theWithHttpTransportcallback. This made it awkward to configure aDistributedCacheEventStreamStorethat got itsIDistributedCachefrom DI.IMcpTaskStorecould be set viaMcpServerOptions.TaskStore, but if set, the SDK then reverse-registered it as a DI singleton.ISessionMigrationHandlerwas resolved exclusively from DI, with no options-based configuration at all.What changed
All three now follow the same pattern:
HttpServerTransportOptionsorMcpServerOptions).IConfigureOptionsimplementation automatically populates it from DI.How to use
ISseEventStreamStore: Register a distributed cache in DI, then callWithDistributedCacheEventStreamStore():To customize store options:
To use a specific
IDistributedCacheinstance (e.g., when multiple caches are registered):IMcpTaskStoreandISessionMigrationHandler: Register an implementation in DI and it will be picked up automatically:Or set them directly on options (explicit values always win):