Skip to content

Conversation

@bokelley
Copy link
Contributor

Summary

  • Handle MCP error responses (isError=True) without requiring structuredContent
  • Extract and display agent error messages from content field for failed calls
  • Keep structuredContent requirement only for successful responses

Test plan

  • ✅ Error response without structuredContent displays agent error message
  • ✅ Success response without structuredContent still raises validation error
  • ✅ Normal successful responses work as before

bokelley and others added 3 commits November 11, 2025 07:26
When an MCP tool returns an error (isError=True), it may only populate
the content field with an error message and leave structuredContent as
None. The SDK now handles this case gracefully by:

1. Checking isError flag before requiring structuredContent
2. Extracting error message from content field for error responses
3. Returning a proper TaskResult with success=False and the error message
4. Only requiring structuredContent for successful responses (isError=False)

This allows the CLI to display agent-provided error messages instead of
raising SDK validation errors.

Updated tests to cover both cases:
- Error responses without structuredContent (now valid)
- Success responses without structuredContent (still invalid)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Split the structuredContent error message across multiple lines
to keep each line under 100 characters for linter compliance.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
MagicMock objects return truthy MagicMock instances for any attribute access,
so mock_result.isError was returning a truthy value even when not explicitly
set. This caused the code to incorrectly treat successful test responses as
errors. Now explicitly setting isError=False for all successful response mocks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bokelley bokelley merged commit 52956bc into main Nov 11, 2025
7 checks passed
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.

2 participants