Use symbolize_names: true in JSON.parse calls

Replace custom `deep_transform_keys` in `Tool::Schema` and
string key access in `StreamableHTTPTransport` with
the `symbolize_names: true` option of `JSON.parse`.

This aligns `StreamableHTTPTransport` with `StdioTransport`,
which already uses `symbolize_names: true`.
This commit is contained in:
Koichi ITO 2026-03-31 03:46:25 +09:00
commit 3a68937bb7

View file

@ -176,7 +176,7 @@ module MCP
body = parse_request_body(body_string)
return body unless body.is_a?(Hash) # Error response
if body["method"] == "initialize"
if body[:method] == "initialize"
handle_initialization(body_string, body)
else
return missing_session_id_response if !@stateless && !session_id
@ -277,17 +277,17 @@ module MCP
end
def parse_request_body(body_string)
JSON.parse(body_string)
JSON.parse(body_string, symbolize_names: true)
rescue JSON::ParserError, TypeError
[400, { "Content-Type" => "application/json" }, [{ error: "Invalid JSON" }.to_json]]
end
def notification?(body)
!body["id"] && !!body["method"]
!body[:id] && !!body[:method]
end
def response?(body)
!!body["id"] && !body["method"]
!!body[:id] && !body[:method]
end
def handle_initialization(body_string, body)