Fix JSON-RPC notification format in Streamable HTTP transport

Update send_notification method to properly construct JSON-RPC notification objects with jsonrpc version and method fields.
This ensures notifications conform to the JSON-RPC 2.0 specification when sent over HTTP transport.

https://www.jsonrpc.org/specification#notification

Another goal is to standardise the `send_notification` interface.
Before the revision, it was sufficient to pass the method and parameters in the case of stdio.
However, in the case of Streamable, a hash based on the JSON-RPC specification must be passed.
This commit is contained in:
dak2 2025-07-26 17:57:51 +09:00
commit e7fafddf94

View file

@ -34,7 +34,13 @@ module MCP
end
end
def send_notification(notification, session_id: nil)
def send_notification(method, params = nil, session_id: nil)
notification = {
jsonrpc: "2.0",
method:,
}
notification[:params] = params if params
@mutex.synchronize do
if session_id
# Send to specific session