Problem
decodeToolResult() parses the first text content item as JSON whenever a result looks like MCP content.
Relevant code:
It does not account for MCP isError, non-JSON text, or structured error reporting.
Impact
Consumers may receive raw SyntaxErrors or lose the distinction between tool failure and malformed responses.
Suggested fix
- Detect
{ isError: true } and throw a structured SDK error containing the tool result.
- Wrap
JSON.parse failures with a helpful message.
- Only parse text as JSON when the response is expected to be JSON.
Acceptance criteria
- Tests cover
isError: true tool results.
- Tests cover non-JSON text content with a clear SDK error.
Problem
decodeToolResult()parses the first text content item as JSON whenever a result looks like MCP content.Relevant code:
src/index.ts:136-153It does not account for MCP
isError, non-JSON text, or structured error reporting.Impact
Consumers may receive raw
SyntaxErrors or lose the distinction between tool failure and malformed responses.Suggested fix
{ isError: true }and throw a structured SDK error containing the tool result.JSON.parsefailures with a helpful message.Acceptance criteria
isError: truetool results.