Invalid UTF-8 in `MCP-Protocol-Version`, `Mcp-Method` or `Mcp-Name` gives 500 instead of 400
Maintainers usually reply within 1 day
@atesgoral is already working on this.
Since Nov 6, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- ruby
- Domain
- backend-api-design
Research direction
Start with lib/mcp/server/transports/streamable_http_transport.rb, especially the cited header handling, decode_header_value, and json_rpc_error_response paths. Reproduce with the supplied Rack request and inspect nearby transport tests for invalid header values. Done means invalid UTF-8 in these headers returns the expected 400 response without a JSON generator exception or exception report.
Written by the indexing model from the issue text.
Description
On the modern path, StreamableHTTPTransport puts raw header values into JSON error bodies:
- the unsupported-version error's
data.requested(streamable_http_transport.rb:908) - the
Mcp-MethodandMcp-Namemismatch messages (:998-1026)
Rack gives header values as binary strings. Also, decode_header_value tags a decoded =?base64?...?= value as UTF-8 without checking it (:1586-1592), so an all-ASCII Mcp-Name: =?base64?/w==?= also produces an invalid string. json_rpc_error_response then calls to_json (:2064-2070), which raises JSON::GeneratorError. The rescue at :968-974 reports the exception and answers 500.
Related: #629 (a reply that cannot be generated gets Internal error) and #609 (another header that caused a 500). Open #654 adds a strict UTF-8 check when it decodes Mcp-Param-* values, but it does not change decode_header_value or these error bodies.
Repro
Run from the repository root with bundle exec ruby -I lib repro.rb:
require "mcp"
require "rack"
reported = []
MCP.configure { |config| config.exception_reporter = ->(error, _context) { reported << error.class } }
server = MCP::Server.new(name: "example")
transport = MCP::Server::Transports::StreamableHTTPTransport.new(server)
env = Rack::MockRequest.env_for(
"http://localhost/",
method: "POST",
input: JSON.generate(jsonrpc: "2.0", id: 1, method: "tools/list"),
"CONTENT_TYPE" => "application/json",
"HTTP_ACCEPT" => "application/json, text/event-stream",
"HTTP_MCP_PROTOCOL_VERSION" => "2026-07-28\xFF".b,
)
status, _headers, body = transport.call(env)
p [status, body.join, reported]
transport.close
Expected: 400 with "Unsupported protocol version", and no exception report. For the Mcp-Method and Mcp-Name cases, 400 with the header mismatch error (-32020).
Actual:
[500, "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32603,\"message\":\"Internal server error\"}}", [JSON::GeneratorError]]
The same 500 happens with invalid bytes in Mcp-Method or Mcp-Name on a modern tools/call, and with Mcp-Name: =?base64?/w==?=.
Suggested fix
Check header values with valid_encoding? (after tagging them as UTF-8) before using them. Leave invalid values out of error bodies, or scrub them. Make decode_header_value refuse a decoded value that is not valid UTF-8, the same way the codec in #654 does.
- Dominant language
- Ruby
- Stars
- 940
- Forks
- 143
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 47
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/ruby-sdk
-
`Client::Stdio` passes the whole parent environment to the server processPossibly taken @atesgoral claimed this today. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 55/100
modelcontextprotocol/ruby-sdk#662 ·
Maintainers usually reply within 1 day
-
Elicitation results are not checked against `requested_schema`, but the docs say they match itPossibly taken @atesgoral claimed this today. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 35/100
modelcontextprotocol/ruby-sdk#661 ·
Maintainers usually reply within 1 day
-
HTTP client sends handler exception messages back to the serverPossibly taken @atesgoral claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
modelcontextprotocol/ruby-sdk#660 ·
Maintainers usually reply within 1 day
-
`JWTVerifier` answers 500 instead of 401 for a PS256 token when it verifies with an EC key (jwt < 3.3.0)Possibly taken @atesgoral claimed this today. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 35/100
modelcontextprotocol/ruby-sdk#659 ·
Maintainers usually reply within 1 day
-
`logging/setLevel` from one session changes the log level of other sessionsPossibly taken @atesgoral claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
modelcontextprotocol/ruby-sdk#658 ·
Maintainers usually reply within 1 day
All issues in modelcontextprotocol/ruby-sdk
Similar issues
-
bug javascript
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
yegor256/netbout.rb#69 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
yegor256/iccq.github.io#161 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
palladius/rails8-app-on-gcp#198 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 95/100
WikiEducationFoundation/WikiEduDashboard#7258 ·
Maintainers usually reply within 1 day