Repository navigation
Conversation
…g out A result that matched no known type failed to decode in the transport, so the response was dropped and the request timed out. Keep such a result as received and fail the request at once with SerializationException.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new internal subtype of the public sealed RequestResult hierarchy breaks consumers’ exhaustive when expressions, so the fallback must be redesigned or the compatibility break and required else branch explicitly documented.
1 open issue
What changed in this PR
This PR changes how the SDK handles unrecognized result shapes: responses reach the pending request and fail with SerializationException instead of timing out. It addresses #1087 while leaving typed extension results for later work.
Changes:
- Preserve unknown result objects in an internal
CustomResult. - Reject those results when completing pending requests.
- Add regression tests for JSON round-tripping and request failure.
| File | Description |
|---|---|
kotlin-sdk-core/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/types/JsonRpcTest.kt |
Tests round-tripping unknown results and preserving metadata. |
kotlin-sdk-core/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/ProtocolTest.kt |
Tests that unknown results cause serialization errors rather than timeouts. |
kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types/serializers.kt |
Adds fallback decoding and serialization for unknown results. |
kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types/request.kt |
Defines the internal raw-result container. |
kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/Protocol.kt |
Completes requests exceptionally when an unknown result arrives. |
Review effort: Balanced
| * A result whose shape matches no known [RequestResult] type, such as a custom method's, kept as received. | ||
| */ | ||
| @Serializable(with = CustomResultSerializer::class) | ||
| internal data class CustomResult(val json: JsonObject) : RequestResult { |
This branch has not been deployed
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.

A response whose result matched no known type failed to decode in the transport, so it was dropped and the request ended with a timeout. Such a result is now kept as received (internal
CustomResult), and the request fails at once withSerializationException. Typed results of extension methods come later, picked by request method (Skills in #1020).How Has This Been Tested?
JsonRpcTestround-trips a response with a result of unknown shape.ProtocolTestchecks that a request with such a result throwsSerializationExceptioninstead of timing out. JVM tests of core, client and server pass, as do the core tests on JS;ProtocolTestandJsonRpcTestalso pass on macosArm64.Breaking Changes
None in the API. A request whose result has an unknown shape now throws
SerializationExceptionat once; before, it timed out withMcpException(REQUEST_TIMEOUT).Closes #1087