modelcontextprotocol / modelcontextprotocol/java-sdk
Servlet-based server transports read request body with wrong charset encoding
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Java
- Star
- 3.7k
- Fork
- 1.1k
- Merge trung bình
- 1 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 9
Mô tả
Bug description
The servlet-based server transports call request.getReader() without first calling request.setCharacterEncoding("UTF-8"). Per the Jakarta Servlet spec, getReader() defaults to ISO-8859-1 when the request's Content-Type doesn't include an explicit charset parameter. Since Content-Type: application/json (without charset) is standard and correct per RFC 8259, any non-ASCII characters in the JSON-RPC request body are silently corrupted.
This affects everything in the request payload — tool names, argument values, notification data — for any MCP client that doesn't redundantly declare charset=utf-8 in its Content-Type header. The analogous issue in StdioServerTransportProvider was fixed in https://github.com/modelcontextprotocol/java-sdk/pull/826.
Environment
- MCP Java SDK: 1.0.0
- Java: 21
- No Spring AI or vector store involved — this is a bug in the core servlet request reading logic, not specific to any framework or integration.
Steps to reproduce
- Start an MCP server using any of the servlet-based transports
- Send a tool call with a non-ASCII string argument, e.g. a unicode escape sequence like \u2014 (em dash —).
- The server receives mojibake (e.g. — → â).
Expected behavior
Non-ASCII characters in the JSON-RPC request body (tool names, argument values, etc.) should be preserved correctly. JSON is UTF-8 by definition, so the server should decode request bodies as UTF-8 regardless of whether the client includes charset=utf-8 in the Content-Type header.
Related
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.
Hướng nghiên cứu
Xác định các triển khai transport dựa trên servlet gọi request.getReader(), sau đó so sánh cách xử lý request body của chúng với bản sửa lỗi StdioServerTransportProvider trong PR 826. Thêm kiểm thử hồi quy sử dụng một giá trị JSON-RPC không phải ASCII và xác minh rằng các request không có charset tường minh vẫn giữ nguyên các ký tự ban đầu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 64/100