🐛 Bug Report: MCP instrumentation crashes on error results with non-text content
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 73/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
Read _execute_and_handle_result() in the MCP instrumentation and inspect how it handles CallToolResult errors; also check InstrumentedStreamWriter.send() for the similar streamed-content assumption. Reproduce with a CallToolResult containing ImageContent, then run the relevant instrumentation tests. Done means non-text error content no longer raises an instrumentation exception and the span records error.type = tool_error.
索引モデルが issue の本文から書いたものです。
説明
Which component is this bug for?
All Packages
📜 Description
opentelemetry-instrumentation-mcp assumes that the first content block in an MCP CallToolResult with isError=True is always a TextContent.
In _execute_and_handle_result(), the instrumentation currently does:
result.content[0].text
when handling an MCP tool error.
However, MCP CallToolResult.content is a list of ContentBlock values and can contain other valid content types such as ImageContent, AudioContent, ResourceLink, or EmbeddedResource.
As a result, a valid MCP error result containing a non-text content block causes the instrumentation itself to raise AttributeError.
For example, this is a valid CallToolResult:
CallToolResult(
content=[
ImageContent(
type="image",
data="aGVsbG8=",
mimeType="image/png",
)
],
isError=True,
)
Passing this result through _execute_and_handle_result() currently raises:
AttributeError: 'ImageContent' object has no attribute 'text'
The span is consequently recorded with error.type = AttributeError, rather than the MCP tool error being represented as a tool_error.
I also found a similar content[0]["text"] assumption in InstrumentedStreamWriter.send() when handling streamed error results, although I have not yet verified whether the same failure is reachable through the streaming path.
👟 Reproduction steps
This can be reproduced without an MCP server, network access, or credentials using a protocol-valid CallToolResult in the instrumentation's result-handling path:
from mcp.types import CallToolResult, ImageContent
result = CallToolResult(
content=[
ImageContent(
type="image",
data="aGVsbG8=",
mimeType="image/png",
)
],
isError=True,
)
# Pass `result` through the MCP instrumentation's
# _execute_and_handle_result() path.
The current implementation attempts to access:
result.content[0].text
and raises:
AttributeError: 'ImageContent' object has no attribute 'text'
The span produced by the instrumentation has:
error.type = AttributeError
instead of treating the MCP result as a tool-level error.
👍 Expected behavior
The instrumentation should handle valid MCP error results regardless of the concrete ContentBlock type, without raising an exception itself.
The tool result should still produce an ERROR span with:
error.type = tool_error
and the instrumentation should not assume that the first content block is TextContent.
👎 Actual Behavior with Screenshots
A valid error result containing a non-text content block causes the instrumentation to raise:
AttributeError: 'ImageContent' object has no attribute 'text'
and the resulting span records:
error.type = AttributeError
This means the instrumentation can mask the actual MCP tool error.
🤖 Python Version
3.12.6
📃 Provide any additional context for the Bug.
Environment:
opentelemetry-instrumentation-mcp: 0.62.4
mcp: 1.26.0
fastmcp: 2.14.3
Python: 3.12.6
mcp==1.26.0 defines CallToolResult.content as a list of MCP content block types rather than a list containing only TextContent.
I have reproduced the failure directly against the current instrumentation code.
There is also a similar content[0]["text"] assumption in the streaming response writer path, which may need to be handled separately.
👀 Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
Are you willing to submit PR?
Yes I am willing to submit a PR!
- 主要言語
- Python
- スター
- 7.5k
- フォーク
- 1.2k
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
traceloop/openllmetry のほかの issue
-
🐛 Bug Report: OpenAI Responses: with_raw_response.create() raises when the body can't be parsed, though the uninstrumented call returns対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug python
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
traceloop/openllmetry#4717 ·
メンテナーはふだん 1 日以内に返信
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentation対応中かも @Quantum-Enigma-dot が 21 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
traceloop/openllmetry#4665 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completions対応中かも @jayfeng7 が 23 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
traceloop/openllmetry#4660 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Bug Report: Failed dataset deletes still remove local rows and columns対応中かも @inchang-ing が 32 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
traceloop/openllmetry#4630 ·
メンテナーはふだん 1 日以内に返信
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penalty対応中かも @shantam77 が 38 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
traceloop/openllmetry#4598 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
traceloop/openllmetry の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
mozilla-ai/cq#601 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
intcomma returns exponential notation for large floats対応中かも @Omarinho12345 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
python-humanize/humanize#521 ·
メンテナーはふだん 1 日以内に返信
-
LUCJ pass manager raises NoEdgeBetweenNodes when an edge is bad for two two-qubit gates対応中かも @hat-im が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
opensubtitlescom: provider rejects pt-PT even though its own converter maps it対応中かも @paulo-0308 が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
Diaoul/subliminal#1405 ·