Merge pull request #435 from koic/fix_result_null_for_id_bearing_notification

Fix an incorrect `result: null` response to an id-bearing notification message
This commit is contained in:
Koichi ITO 2026-07-02 07:40:40 +09:00 • committed by GitHub
commit 49d6d7f254
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -430,6 +430,13 @@ module MCP
end
def handle_request(request, method, session: nil, related_request_id: nil)
# A well-formed notification carries no JSON-RPC id and receives no response.
# If a client erroneously sends a notification-only method with an id, the message
# is framed as a request; since notification methods have no request handler,
# returning `nil` here makes `JsonRpcHandler` report "Method not found", matching
# the TypeScript and Python SDKs rather than emitting a spurious `result: null`.
return if Methods.notification?(method) && !related_request_id.nil?
# `notifications/cancelled` is dispatched directly: it is a notification (no JSON-RPC id)
# and intentionally bypasses the `@handlers` lookup, capability check, in-flight registry,
# and rescue blocks below.