Skip to content

ProxyTool crashes on non-TextContent error responses #3922

@strawgate

Description

@strawgate

When a proxied server returns an error with non-TextContent (e.g., ImageContent), ProxyTool.run() crashes with AttributeError.

The error path in proxy.py does:

if result.isError:
    raise ToolError(cast(mcp.types.TextContent, result.content[0]).text)

cast() is a no-op at runtime — if content[0] is ImageContent or EmbeddedResource, accessing .text raises AttributeError.

Reproduction:

import mcp.types
result = mcp.types.CallToolResult(
    isError=True,
    content=[mcp.types.ImageContent(type="image", data="abc", mimeType="image/png")]
)
result.content[0].text  # AttributeError: 'ImageContent' object has no attribute 'text'

Fix: check isinstance(content, TextContent) before accessing .text, fall back to str(content) for other types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.serverRelated to FastMCP server implementation or server-side functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions