fix(mcp): extract error message from content[0].text per MCP 1.4.0 protocol #2600

Merged
freemo merged 1 commits from fix/mcp-adapter-error-extraction-content-key into master 2026-04-03 20:40:10 +00:00

1 Commits

Author SHA1 Message Date
freemo b96138b88e fix(mcp): extract error message from content[0].text per MCP 1.4.0 protocol
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 20s
CI / typecheck (pull_request) Successful in 50s
CI / quality (pull_request) Successful in 38s
CI / helm (pull_request) Successful in 23s
CI / build (pull_request) Successful in 3m16s
CI / security (pull_request) Successful in 4m9s
CI / unit_tests (pull_request) Failing after 6m26s
CI / docker (pull_request) Has been skipped
CI / coverage (pull_request) Successful in 10m11s
CI / e2e_tests (pull_request) Failing after 15m10s
CI / integration_tests (pull_request) Failing after 21m56s
CI / status-check (pull_request) Failing after 1s
CI / benchmark-regression (pull_request) Successful in 56m11s
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