modelcontextprotocol / modelcontextprotocol/java-sdk
Servlet-based server transports read request body with wrong charset encoding
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 3.7k
- フォーク
- 1.1k
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 9
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
request.getReader() を呼び出しているサーブレットベースのトランスポート実装を特定し、それらのリクエストボディの処理を PR 826 の StdioServerTransportProvider の修正と比較します。非 ASCII の JSON-RPC 値を使用したリグレッションテストを追加し、明示的な charset のないリクエストで元の文字が保持されることを検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 64/100