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:
commit
49d6d7f254
2 changed files with 133 additions and 0 deletions
|
|
@ -47,6 +47,10 @@ module MCP
|
|||
end
|
||||
|
||||
class << self
|
||||
def notification?(method)
|
||||
method.is_a?(String) && method.start_with?("notifications/")
|
||||
end
|
||||
|
||||
def ensure_capability!(method, capabilities)
|
||||
case method
|
||||
when PROMPTS_GET, PROMPTS_LIST
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue