Visitar URL original
fix(mcp): retain exception type for empty tool error messages by feiiiiii5 · Pull Request #1462 · anthropics/claude-agent-sdk-python · GitHub
Skip to content

fix(mcp): retain exception type for empty tool error messages - #1462

Open
feiiiiii5 wants to merge 1 commit into
anthropics:mainfrom
feiiiiii5:codex/mcp-empty-tool-error
Open

feiiiiii5 wants to merge 1 commit into
anthropics:mainfrom
feiiiiii5:codex/mcp-empty-tool-error

Conversation

@feiiiiii5

Copy link
Copy Markdown

When an SDK MCP tool raises an exception with an empty message, such as TimeoutError(), its error result contains an empty text block. The model receives isError: true without any explanation.

Fall back to the exception type name when str(e) is empty, matching Query._handle_sdk_mcp_request. Exceptions with a message keep their existing text.

The regression calls the tool through Query, the in-memory JSON-RPC connection and the real MCP server. Against main 1ea8cb74, it fails on both asyncio and Trio: [''] != ['TimeoutError']. With this one-line fix, python -m pytest tests/test_sdk_mcp_integration.py -q passes 144 tests with both MCP 2.3.0 and the supported 1.23.0 floor (Python 3.13.3).

Also passed ruff check src/ tests/ scripts/ and ruff format --check src/ tests/ scripts/. mypy src/ scripts/ passed with both MCP versions. No live Claude API or CLI was used. Upstream CI has not run yet.

An SDK MCP tool handler that raises an empty-message exception (e.g. 'raise TimeoutError()') produced an error result whose text was an empty string, so the model could see that the tool failed but not why. Fall back to the exception type name, matching the existing fallback in Query._handle_sdk_mcp_request, so create_sdk_mcp_server's 'isError results the model can read' note holds.
@feiiiiii5

Copy link
Copy Markdown
Author

The empty-message MCP tool error fallback is green through Query and the real MCP server on both MCP 2.3.0 and the 1.23.0 floor. Is falling back to the exception type name the behavior you want for an empty str(e), or should the empty text stay and the error be surfaced on another field?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant