🐛 Bug Report: MCP instrumentation crashes on error results with non-text content
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 73/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- observability
Research direction
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.
Written by the indexing model from the issue text.
Description
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!
- Dominant language
- Python
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from traceloop/openllmetry
-
bug python
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
traceloop/openllmetry#4717 ·
Maintainers usually reply within 1 day
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentationPossibly taken @Quantum-Enigma-dot claimed this 21 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
traceloop/openllmetry#4665 · 1 comment ·
Maintainers usually reply within 1 day
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completionsPossibly taken @jayfeng7 claimed this 23 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
traceloop/openllmetry#4660 · 1 comment ·
Maintainers usually reply within 1 day
-
Bug Report: Failed dataset deletes still remove local rows and columnsPossibly taken @inchang-ing claimed this 32 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
traceloop/openllmetry#4630 ·
Maintainers usually reply within 1 day
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penaltyPossibly taken @shantam77 claimed this 38 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
traceloop/openllmetry#4598 · 2 comments ·
Maintainers usually reply within 1 day
All issues in traceloop/openllmetry
Similar issues
-
opensubtitlescom: provider rejects pt-PT even though its own converter maps itPossibly taken @paulo-0308 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Diaoul/subliminal#1405 ·
-
Internal ErrorOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
frappe/frappe_docker#2071 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
The-Pocket/PocketFlow#161 ·
-
comp/desktop P2 type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NousResearch/hermes-agent#157702 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
zai-org/zcode-plugins#202 ·
Maintainers usually reply within 1 day