Skip to content

Fix an incorrect result: null response to an id-bearing notification message#435

Open
koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:fix_result_null_for_id_bearing_notification
Open

Fix an incorrect result: null response to an id-bearing notification message#435
koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:fix_result_null_for_id_bearing_notification

Conversation

@koic

@koic koic commented Jun 30, 2026

Copy link
Copy Markdown
Member

Motivation and Context

A JSON-RPC notification carries no id and must not receive any response. When a client erroneously sent a notification-only method such as notifications/cancelled with an id, the server replied with a successful result: null, which is neither a valid MCP result nor a legal reply to a notification.

Such a message is now treated as a request for a method that has no request handler and rejected with Method not found, matching the behavior of the TypeScript and Python SDKs. A well-formed notification that omits the id continues to receive no response.

Fixes #434.

How Has This Been Tested?

Added regression tests covering id-bearing notifications/cancelled, notifications/initialized, and notifications/progress, a batch that mixes an id-bearing notification with other messages, custom notifications/* methods, and the same case over the HTTP transport.

Breaking Changes

None for spec-conformant clients, which never put an id on a notification. The only behavioral change is that a malformed id-bearing notification now receives a Method not found error instead of a spurious result: null.

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

…n message

## Motivation and Context

A JSON-RPC notification carries no id and must not receive any response.
When a client erroneously sent a notification-only method such as `notifications/cancelled` with an id,
the server replied with a successful `result: null`, which is neither a valid MCP result nor
a legal reply to a notification.

Such a message is now treated as a request for a method that has no request handler and rejected with
Method not found, matching the behavior of the TypeScript and Python SDKs. A well-formed notification
that omits the id continues to receive no response.

Fixes modelcontextprotocol#434.

## How Has This Been Tested?

Added regression tests covering id-bearing `notifications/cancelled`, `notifications/initialized`,
and `notifications/progress`, a batch that mixes an id-bearing notification with other messages,
custom `notifications/*` methods, and the same case over the HTTP transport.

## Breaking Changes

None for spec-conformant clients, which never put an id on a notification.
The only behavioral change is that a malformed id-bearing notification now receives a Method not found error
instead of a spurious `result: null`.
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.

Ruby SDK returns result: null for an id-bearing notifications/cancelled message

2 participants