mcp-server-fetch: `fetch` prompt returns JSON-RPC error code 0 with the raw exception text for an invalid URL
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
- #4918 @DawnofGenX による — マージされずにクローズ
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
調査の方向性
server.py の127行目と262-288行目から始め、その後、issue に示されている不正な URL を使って prompts/get リクエストを再現します。プロンプトの処理を、ツールで使用されている Fetch モデルのバリデーションと比較し、無効な入力が明確なメッセージとともに JSON-RPC -32602 を返し、有効な URL では引き続きページコンテンツが返されることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
The fetch tool validates url through the Fetch model, so a malformed URL comes back as a normal isError: true result. The fetch prompt passes arguments["url"] straight to fetch_url (server.py:262-265) and catches only McpError (server.py:267). fetch_url converts only httpx.HTTPError (server.py:127), and httpx.InvalidURL is not an HTTPError, so it escapes both handlers. With raise_exceptions=False (server.py:288), the SDK's low-level server then answers with a JSON-RPC error whose code is 0 and whose message is the raw exception text.
To Reproduce
mcp-server-fetch 0.6.3 (commit f46d957), mcp 1.29.0 (as in uv.lock), Python 3.14, Windows 11. After initialize, send over stdio:
{"jsonrpc": "2.0", "id": 3, "method": "prompts/get", "params": {"name": "fetch", "arguments": {"url": "http://[::1"}}}
Response:
{"jsonrpc": "2.0", "id": 3, "error": {"code": 0, "message": "Invalid port: ':1'"}}
The same URL through the tool is handled cleanly:
{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "fetch", "arguments": {"url": "http://[::1"}}}
isError: true — "1 validation error for Fetch\nurl\n Input should be a valid URL, invalid IPv6 address ..."
Expected behavior
An invalid prompt argument should produce a proper parameter error (-32602, INVALID_PARAMS) with a clear message, consistent with the tool. Code 0 is the SDK's generic fallback for unhandled exceptions, so a client can't tell a bad argument from a server fault.
Suggested fix
Validate the prompt's url the same way the tool does before fetching:
url = arguments["url"] # current code; replace with:
try:
url = str(Fetch(url=arguments["url"]).url)
except ValueError as e:
raise McpError(ErrorData(code=INVALID_PARAMS, message=str(e)))
With this change, the request above returns -32602 with the validation message, and a valid URL still returns the page content (checked locally).
Additional context
Related: #3359 / #3515 (malformed input handling). I found this while testing a static checker for MCP error handling, then reproduced it by hand with a raw JSON-RPC client (no MCP client library involved). Happy to open a PR with this change if that's useful.
- 主要言語
- JavaScript
- スター
- 91.2k
- フォーク
- 11.8k
- 平均マージ
- 6時間 39分
- マージ済み PR(30日)
- 111
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/servers のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
modelcontextprotocol/servers#5134 ·
メンテナーはふだん 1 日以内に返信
-
documentation v2
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
modelcontextprotocol/servers#5133 ·
メンテナーはふだん 1 日以内に返信
-
sequentialthinking: the thought box's header row is 2 columns narrower than its border対応中かも @nightcityblade が 2 日前に担当しました。 オープンbug server-sequentialthinking v2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/servers#5108 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
bug server-git v2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/servers#5107 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
modelcontextprotocol/servers#5071 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/servers の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
[quality] Nothing keeps docs/skills/manifest.md in sync with docs/skills/*.md対応中かも @hivecommons-hive が今日担当しました。 オープンagent/quality hive/covered-by-pr hive/hosted-available-lke648397-260827-5n31 quality testing
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
apache/rocketmq-dashboard#6610 ·
メンテナーはふだん 3 日以内に返信
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
githubnext/gh-aw-workshop#4535 ·
メンテナーはふだん 1 日以内に返信
-
Global update drops overrideAccess, so Local API updateGlobal fails filterOptions validation (3.90 regression)対応中かも @PINYOPATTANAWASANPORN が今日担当しました。 オープンarea: core Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
payloadcms/payload#18674 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信