Skip to content

fix: classify malformed request params as invalid params#886

Merged
devcrocod merged 2 commits into
modelcontextprotocol:mainfrom
jstar0:fix/initialize-param-error-codes
Jul 22, 2026
Merged

fix: classify malformed request params as invalid params#886
devcrocod merged 2 commits into
modelcontextprotocol:mainfrom
jstar0:fix/initialize-param-error-codes

Conversation

@jstar0

@jstar0 jstar0 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Classify typed request deserialization failures as JSON-RPC Invalid Params
instead of Internal error.

Fixes #830.

Changes

  • translate SerializationException from typed request decoding to -32602
  • return a stable Invalid params message without serialization internals
  • cover malformed initialize requests through session and Streamable HTTP paths

Scope and risk

The catch is limited to request parameter deserialization after the JSON-RPC
method has been resolved. Envelope parsing, unknown methods, handler failures,
and successful requests keep their existing behavior.

Verification

./gradlew :integration-test:jvmTest --tests 'io.modelcontextprotocol.kotlin.sdk.server.ServerSessionInitializeTest'
./gradlew :kotlin-sdk-server:jvmTest --tests 'io.modelcontextprotocol.kotlin.sdk.server.StreamableHttpServerTransportTest'
./gradlew :kotlin-sdk-core:jvmTest --tests 'io.modelcontextprotocol.kotlin.sdk.shared.ProtocolTest'
./gradlew ktlintCheck apiCheck

@jstar0
jstar0 force-pushed the fix/initialize-param-error-codes branch from b42065e to b43aadc Compare July 15, 2026 15:04

@devcrocod devcrocod 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.

lgtm

@devcrocod
devcrocod merged commit cab669b into modelcontextprotocol:main Jul 22, 2026
19 checks passed
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.

Malformed initialize request with missing required params returns different JSON-RPC error codes per transport

2 participants