Fix #348: Allow ToolError to carry custom content and is_error#2708
Open
Stoobyy wants to merge 1 commit into
Open
Fix #348: Allow ToolError to carry custom content and is_error#2708Stoobyy wants to merge 1 commit into
Stoobyy wants to merge 1 commit into
Conversation
ad6c854 to
1be32b4
Compare
… and is_error Adds `content` and `is_error` parameters to ToolError so tool functions can return arbitrary content blocks with isError=True (e.g., images, structured data alongside error status). - exceptions.py: ToolError gains content and is_error parameters - tools/base.py: Re-raise ToolError instead of wrapping it - server.py: Catch ToolError, construct CallToolResult with proper content - tests: 2 new tests covering ToolError with custom content and default Closes modelcontextprotocol#348 Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
1be32b4 to
f879ec6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Closes #348. There is currently no way to set
isError=Truewhen returning non-text content from tool calls (e.g., images, mixed content). The only way to getisError=Trueis to let an unhandled exception propagate, which always produces a singleTextContentblock.What changed
ToolErrornow acceptscontentandis_errorkeyword argumentsTool.run()re-raisesToolErrorinstead of wrapping it_handle_call_toolcatchesToolErrorbefore the generic exception handler, constructing aCallToolResultwith the caller's custom content andis_errorvalueUsage
Validation