Files
temp/features/tdd_mcp_error_content_key.feature
freemo b96138b88e fix(mcp): extract error message from content[0].text per MCP 1.4.0 protocol
MCPToolAdapter.invoke() was reading error messages from result.get('error',
'unknown error'), but the MCP 1.4.0 protocol returns errors in the content
field as a list of content items with type and text keys. This caused every
error from a real MCP 1.4.0-compliant server to be silently replaced with
the string 'unknown error'.

Changes:
- src/cleveragents/mcp/adapter.py: extract error_text from content[0].text
  with safe guards (isinstance check, length check) and fallback to
  'unknown error' when content is absent or empty
- features/mocks/mock_mcp_transport.py: return MCP 1.4.0-compliant error
  responses using content list format instead of the non-standard error key
- features/tdd_mcp_error_content_key.feature: Behave scenario verifying
  correct error extraction from MCP 1.4.0 content arrays (written as TDD
  issue-capture, @tdd_expected_fail removed after fix applied)
- features/steps/tdd_mcp_error_content_key_steps.py: step definitions for
  the new scenario including _MCP14ErrorTransport mock subclass

All 51 MCP adapter scenarios pass. Typecheck: 0 errors. Lint: clean.

ISSUES CLOSED: #2158
2026-04-03 19:03:15 +00:00

12 lines
736 B
Gherkin

@tdd_issue @tdd_issue_2158
Feature: TDD Issue #2158 — MCPToolAdapter.invoke() error extraction uses non-standard key
MCPToolAdapter.invoke() currently reads error messages from result.get('error', 'unknown error'),
but the MCP 1.4.0 protocol returns errors in content[0].text. This means every error from a
real MCP 1.4.0 server is silently replaced with "unknown error".
Scenario: invoke() extracts error message from MCP 1.4.0 content array
Given a connected MCP adapter with a tool returning MCP 1.4.0 content-based error "read_file"
When I invoke "read_file" with arguments {"path": "/path/to/file"}
Then the invocation should fail
And the invocation error should contain "File not found: /path/to/file"