Add isError support for non-text tool results (Fixes #348) - #3370
Add isError support for non-text tool results (Fixes #348)#3370mukktinaadh wants to merge 2 commits into
Conversation
…lback - Add new callback to ClientSession and Client for handling transport-level exceptions (timeouts, connection errors) - Update to use the new handler with fallback to for backwards compatibility - Make default log transport exceptions at ERROR level - Add tests for the new callback and fallback behavior Fixes modelcontextprotocol#1401
…ocol#348) - Add CallToolResult.create_error() classmethod for convenient error results with non-text content - Add model_validator to auto-convert SDK Image/Audio helpers to wire content types - Allow Image/Audio helpers directly in CallToolResult.content - Add tests for image, audio, and structured content error results
|
Thanks for the contribution. This repository only keeps pull requests open when they're linked to an issue that a maintainer has assigned to the author — CONTRIBUTING.md explains why and how we work. This PR has been closed for now because its description doesn't yet link an open issue in this repository (with If there isn't an issue for this yet, please open one — a clear description of the problem is genuinely the most useful thing for us. Then add There's no need to open a new PR — this one will be reopened. While it's closed, please push any updates as new commits rather than force-pushing, since GitHub can't reopen a PR whose branch has been rewritten. Maintainers: reopening this PR, removing the |
Summary
This PR addresses issue #348 by adding support for returning tool errors with non-text content (images, audio, structured data) without raising exceptions.
Changes
Core Changes (
src/mcp-types/mcp_types/_types.pyand version-specific models)CallToolResult.create_error()classmethod for creating error results with non-text contentmodel_validatorto auto-convert SDK Image/Audio helpers to their wire content types (ImageContent,AudioContent)Server Integration (
src/mcp/server/mcpserver/utilities/func_metadata.py)convert_resultto handle Image/Audio helpers when passed directly inCallToolResult.contentTests (
tests/server/mcpserver/tools/test_base.py)Usage Example
Backwards Compatibility
CallToolResultwithis_error=Truecontinues to workTesting
All 5,747 existing tests pass + 3 new tests added for the new functionality.