Invalid UTF-8 in `MCP-Protocol-Version`, `Mcp-Method` or `Mcp-Name` gives 500 instead of 400
Maintainer thường phản hồi trong vòng 1 ngày
@atesgoral đang làm issue này rồi.
Từ ngày 6/11/2026.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- ruby
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Bắt đầu với lib/mcp/server/transports/streamable_http_transport.rb, đặc biệt là phần xử lý các header được nêu và các nhánh decode_header_value, json_rpc_error_response. Tái hiện bằng yêu cầu Rack được cung cấp và kiểm tra các bài kiểm thử transport gần đó để tìm các giá trị header không hợp lệ. Hoàn thành khi UTF-8 không hợp lệ trong các header này trả về phản hồi 400 như mong đợi mà không gây ra ngoại lệ của bộ tạo JSON hoặc báo cáo ngoại lệ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Ruby
- Star
- 940
- Fork
- 143
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 47
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/ruby-sdk
-
`Client::Stdio` passes the whole parent environment to the server processCó thể đã có người làm @atesgoral đã nhận hôm nay. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
modelcontextprotocol/ruby-sdk#662 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Elicitation results are not checked against `requested_schema`, but the docs say they match itCó thể đã có người làm @atesgoral đã nhận hôm nay. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
modelcontextprotocol/ruby-sdk#661 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
HTTP client sends handler exception messages back to the serverCó thể đã có người làm @atesgoral đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
modelcontextprotocol/ruby-sdk#660 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`JWTVerifier` answers 500 instead of 401 for a PS256 token when it verifies with an EC key (jwt < 3.3.0)Có thể đã có người làm @atesgoral đã nhận hôm nay. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
modelcontextprotocol/ruby-sdk#659 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`logging/setLevel` from one session changes the log level of other sessionsCó thể đã có người làm @atesgoral đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
modelcontextprotocol/ruby-sdk#658 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/ruby-sdk
Issue tương tự
-
bug javascript
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
yegor256/netbout.rb#69 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
yegor256/iccq.github.io#161 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
palladius/rails8-app-on-gcp#198 ·
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
WikiEducationFoundation/WikiEduDashboard#7258 ·
Maintainer thường phản hồi trong vòng 1 ngày