Merge pull request #448 from koic/handle_non_object_json_rpc_messages

Handle non-object JSON-RPC messages without raising
This commit is contained in:
Koichi ITO 2026-07-12 02:12:46 +09:00 • committed by GitHub
commit 3d442d0a65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -134,6 +134,27 @@ module MCP
end
end
test "open handles a malformed JSON-RPC batch element and emits an error response" do
input = StringIO.new("[[]]\n")
output = StringIO.new
original_stdin = $stdin
original_stdout = $stdout
begin
$stdin = input
$stdout = output
@transport.open
response = JSON.parse(output.string, symbolize_names: true)
assert_nil(response[:id])
assert_equal(-32600, response[:error][:code])
assert_equal("Invalid Request", response[:error][:message])
ensure
$stdin = original_stdin
$stdout = original_stdout
end
end
test "rejects duplicate initialize on the same stdio session with -32600" do
first = {
jsonrpc: "2.0",