Skip to content

fix: retain streamable HTTP session on response write failure#972

Open
DragonFSKY wants to merge 1 commit into
modelcontextprotocol:mainfrom
DragonFSKY:fix/952-streamable-session-retained
Open

fix: retain streamable HTTP session on response write failure#972
DragonFSKY wants to merge 1 commit into
modelcontextprotocol:mainfrom
DragonFSKY:fix/952-streamable-session-retained

Conversation

@DragonFSKY
Copy link
Copy Markdown

Fixes #952.

Summary

  • Keep the MCP session registered when a request-specific streamable HTTP response write fails.
  • Continue completing the failed request async context without treating the write failure as an explicit session termination.
  • Add a regression test that simulates PrintWriter.checkError() after an SSE response write and verifies a subsequent request using the same session id does not return 404.

Verification

  • ./mvnw -pl mcp-test -am -Dtest=HttpServletStreamableSessionFailureTests -Dsurefire.failIfNoSpecifiedTests=false test
  • ./mvnw -pl mcp-test -am -Dtest=HttpServletStreamableSessionFailureTests,HttpServletStreamableSyncServerTests,HttpServletStreamableAsyncServerTests,HttpServletStreamableIntegrationTests -Dsurefire.failIfNoSpecifiedTests=false test
  • ./mvnw -pl mcp-core,mcp-test -am spring-javaformat:validate
  • git diff --check

Kehrlann pushed a commit to joaodinissf/java-sdk that referenced this pull request May 28, 2026
modelcontextprotocol#972)

The MCP specification evolves continuously; domain types must absorb
new fields and subtypes without breaking existing clients or servers.
On the 1.x line this is structurally prevented by sealed interfaces,
which make it impossible to add a permitted subtype without breaking
exhaustive pattern-match switch expressions in caller code. This
commit opens the 2.0 release line, where those constraints are lifted
and serialization is made self-contained — independent of any global
ObjectMapper configuration.

Breaking changes for users migrating from 1.x

- Sealed interfaces removed from JSONRPCMessage, Request, Result,
  Notification, ResourceContents, CompleteReference and Content.
  Exhaustive switch expressions over these types must add a default
  branch.
- Prompt(name, description, null) no longer silently coerces null
  arguments to an empty list. Use Prompt.withDefaults() to preserve
  the previous behaviour.
- CompleteCompletion.total and .hasMore are now absent from the wire
  when not set, rather than being emitted as null.
- ServerParameters no longer carries Jackson annotations; it is an
  internal configuration class, not a wire type.

What now works that did not before

- CompleteReference polymorphic dispatch (PromptReference vs
  ResourceReference) works through a plain readValue or convertValue
  call — no hand-rolled map inspection required.
- LoggingLevel deserialization is lenient: unknown level strings
  produce null instead of throwing.
- All domain records now tolerate unknown JSON fields, so a client
  built against an older SDK version will not fail when a newer server
  sends fields it does not yet recognise.
- Null optional fields are consistently absent from serialized output
  regardless of ObjectMapper configuration.

Documentation

- CONTRIBUTING adds an "Evolving wire-serialized records" section: a
  9-rule recipe and example for adding a field safely.
- MIGRATION-2.0 documents all breaking changes listed above.

Follow-up coming next

Several spec-required fields (e.g. JSONRPCError.code/message,
ProgressNotification.progress, CreateMessageRequest.maxTokens,
CallToolResult.content) are stored as nullable Java types without a
null guard. If constructed with null, the NON_ABSENT rule silently
omits them, producing invalid wire JSON without throwing. Fix: compact
canonical constructors with Assert.notNull, following the pattern
already in JSONRPCRequest.

Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpServletStreamableServerTransportProvider removes session on non-fatal failure

1 participant