feat: add McpSessionStore SPI for pluggable session storage#914
Open
vlin529 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
feat: add McpSessionStore SPI for pluggable session storage#914vlin529 wants to merge 1 commit intomodelcontextprotocol:mainfrom
vlin529 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Introduce a `McpSessionStore` interface that abstracts session storage, enabling custom implementations (e.g., Redis, JDBC) for distributed and multi-instance MCP server deployments. Changes: - Add `McpSessionStore` interface with save/get/remove/values/clear ops - Add `InMemoryMcpSessionStore` as the default ConcurrentHashMap-backed implementation (preserving existing behavior) - Refactor `HttpServletStreamableServerTransportProvider` to use `McpSessionStore` instead of a hardcoded ConcurrentHashMap - Add `sessionStore()` method to the Builder for custom store injection - Default to `InMemoryMcpSessionStore` when no custom store is provided This is a non-breaking change: existing code continues to work without modification as the default in-memory store is used automatically. Closes modelcontextprotocol#274 Relates to modelcontextprotocol#107, modelcontextprotocol#738, modelcontextprotocol#376
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduce a
McpSessionStoreinterface that abstracts session storage inHttpServletStreamableServerTransportProvider, enabling custom implementations (e.g., Redis, JDBC, Hazelcast) for distributed and multi-instance MCP server deployments.Problem
Currently,
HttpServletStreamableServerTransportProviderstores sessions in a hardcodedConcurrentHashMap. This causes:sessionsfield isprivate final, methods areprivate, Builder has nosessionStore()optionRelated issues: #274, #107, #738, #376
Changes
McpSessionStore— new interface withsave/get/remove/values/isEmpty/size/clearoperationsInMemoryMcpSessionStore— defaultConcurrentHashMap-backed implementation (preserves existing behavior)HttpServletStreamableServerTransportProvider— refactored to useMcpSessionStoreinstead of hardcodedConcurrentHashMapsessionStore(McpSessionStore)method for custom store injection; defaults toInMemoryMcpSessionStorewhen not setUsage
Non-breaking
This is a fully backward-compatible change. Existing code continues to work without modification — the default
InMemoryMcpSessionStoreis used when no custom store is provided.Test
All 274 existing mcp-core tests pass.
Closes #274
Relates to #107, #738, #376