| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Tool authors can now raise ToolError(content=[...]) to return a CallToolResult with is_error=True that carries arbitrary content (e.g. an image or embedded resource) instead of only the error message as text. A plain ToolError behaves exactly as before. content is typed as list[Any] rather than list[ContentBlock] because exceptions.py is imported during mcp package initialization, before mcp.types is importable - referencing that type would create a circular import. Closes modelcontextprotocol#348
|
Good enhancement! Letting ToolError carry structured content (images, embedded resources) is useful for rich error responses. The circular import avoidance note is a smart documentation touch. |
Sorry, something went wrong.
There was a problem hiding this comment.
Verified locally on Python 3.12 (Windows) against PR head 9b6b9af.
Verdict: approve — the change is additive, backward compatible, and behaves as intended for valid input.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Closes #348.
Tool authors currently have no way to return a CallToolResult with is_error=True that carries non-text content — raising an exception only surfaces the message as text. This implements the approach @Kludex suggested in the issue: give ToolError an optional content field that is translated to the error result internally.
What changed
A plain ToolError("...") behaves exactly as before — this is purely additive and non-breaking.
Tests / checks
Disclosure
Developed with AI assistance. I've reviewed the change and can explain every line.