Skip to content

fix: allow deserializing notifications without params field#729

Open
DaleSeo wants to merge 1 commit intomainfrom
fix/notification-no-params-deserialization
Open

fix: allow deserializing notifications without params field#729
DaleSeo wants to merge 1 commit intomainfrom
fix/notification-no-params-deserialization

Conversation

@DaleSeo
Copy link
Member

@DaleSeo DaleSeo commented Mar 7, 2026

Fixes #703

Motivation and Context

The JSON-RPC 2.0 spec makes params optional in notifications, but Notification::deserialize was using Proxy, which requires that field to be present. This led to users getting an untagged enum deserialization error when calling serde_json::from_slice::<JsonRpcMessage>(&body) with the bare JsonRpcMessage type on notifications that didn't include params, like notifications/initialized. The typed aliases, such as ClientJsonRpcMessage, weren't affected because they go through NotificationNoParam for notifications without parameters.

To fix this, we switched Notification::deserialize to use the existing ProxyOptionalParam. Now, when params is missing, it treats it as an empty object {} before deserializing into R.

How Has This Been Tested?

Added a regression test

Breaking Changes

None. This is a pure bug fix. Previously failing parses now succeed, and all existing behaviour for notifications with params is unchanged.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@DaleSeo DaleSeo self-assigned this Mar 7, 2026
@github-actions github-actions bot added T-core Core library changes T-model Model/data structure changes labels Mar 7, 2026
@DaleSeo DaleSeo marked this pull request as ready for review March 7, 2026 03:06
@DaleSeo DaleSeo requested a review from a team as a code owner March 7, 2026 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-model Model/data structure changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notification initialized parse error

1 participant