Tools returning NaN or inf still fail on the client (follow-up to #3341)
メンテナーはふだん 1 日以内に返信
@Jeremy891102 がすでに取り組んでいます。
2026年11月24日 から。
評価
調査の方向性
Start from _dump_result in runner.py, which turns nan/inf into null during the outbound dump; follow the value to the client-side validation of structured_content against the tool output schema, where the RuntimeError in the reproduction is raised. Run the example script against a local checkout to confirm the failure on main. Done means the call no longer raises for non-finite floats — either a usable result or an isError: true tool error naming the value — with a regression test alongside the existing call_tool tests; the approach still needs a maintainer decision, since the thread has no agreed direction yet.
索引モデルが issue の本文から書いたものです。
説明
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Release line
2.x (current stable)
Description
A tool that returns a non-finite float (nan, inf, -inf) makes call_tool raise on the client, so the whole result is lost. This was reported in #3341 and labeled bug, but #3341 was later closed as not planned by its author, and the related fix for text content (#3429, for #3385) was closed by the issue-link bot. It still reproduces on 2.3.0 and on main (77001c9).
This comes up a lot with ML tools: an evaluation tool that returns a metrics model loses every metric when one of them is undefined, for example AUC on a subgroup that contains only one class.
What happens: the server keeps nan in structured_content, the outbound dump turns it into null (the analysis in #3341 points at _dump_result in runner.py), and the client then validates null against the tool's own output schema ("type": "number") and raises RuntimeError: Invalid structured content returned by tool ..., which surfaces wrapped in an ExceptionGroup.
Expected: the call returns a result the client can use, or a tool error result (isError: true) that names the non-finite value, as suggested in #3341, instead of an exception on the client.
If a fix along those lines is welcome, I'd like to work on it.
I used an AI assistant to find and reproduce this and to draft this report.
Example Code
import math
import anyio
from pydantic import BaseModel
from mcp import Client
from mcp.server import MCPServer
mcp = MCPServer("nan-demo")
class Metrics(BaseModel):
accuracy: float
auc: float
@mcp.tool()
def evaluate() -> Metrics:
# AUC is undefined when the evaluation set contains a single class
return Metrics(accuracy=0.9, auc=math.nan)
async def main():
async with Client(mcp) as client:
await client.call_tool("evaluate", {})
anyio.run(main)
# ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
# RuntimeError: Invalid structured content returned by tool evaluate: None is not of type 'number'
Python & MCP Python SDK
Python 3.13.18
mcp 2.3.0 (also reproduces on main at 77001c9)
pydantic 2.13.5
- 主要言語
- Python
- スター
- 25k
- フォーク
- 4.2k
- 平均マージ
- 10分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/python-sdk のほかの issue
-
v2
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
modelcontextprotocol/python-sdk#3978 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Client serves cached tools after its context exits with an exception対応中かも @jonxsong が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
modelcontextprotocol/python-sdk#3968 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
modelcontextprotocol/python-sdk#3957 ·
メンテナーはふだん 1 日以内に返信
-
v2
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
modelcontextprotocol/python-sdk#3934 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
bug v1
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
modelcontextprotocol/python-sdk#3929 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/python-sdk の issue をすべて見る
似ている issue
-
auto-reported bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
stix-atlas.json: the same relationship id is used for several different mitigates relationshipsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
backend bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
nolte/kamerplanter#3193 ·
メンテナーはふだん 1 日以内に返信
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwise対応中かも @abdulwaarith0 が今日担当しました。 オープンneeds-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
MakazhanAlpamys/Soup#3690 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信