Skip to content

P2: Improve MCP text response decoding and error handling #2

@vamgan

Description

@vamgan

Problem

decodeToolResult() parses the first text content item as JSON whenever a result looks like MCP content.

Relevant code:

  • src/index.ts:136-153

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions