Skip to content

fix(core): fail requests on results of unknown shape instead of timing out - #1186

Open
devcrocod wants to merge 1 commit into
mainfrom
devcrocod/extension-method-results
Open

devcrocod wants to merge 1 commit into
mainfrom
devcrocod/extension-method-results

Conversation

@devcrocod

Copy link
Copy Markdown
Contributor

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 with SerializationException. Typed results of extension methods come later, picked by request method (Skills in #1020).

How Has This Been Tested?

JsonRpcTest round-trips a response with a result of unknown shape. ProtocolTest checks that a request with such a result throws SerializationException instead of timing out. JVM tests of core, client and server pass, as do the core tests on JS; ProtocolTest and JsonRpcTest also pass on macosArm64.

Breaking Changes

None in the API. A request whose result has an unknown shape now throws SerializationException at once; before, it timed out with McpException (REQUEST_TIMEOUT).

Closes #1087

…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.
Copilot AI balanced review requested due to automatic review settings November 16, 2026 15:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

No deployments
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.

The client cannot receive results of extension methods

2 participants