Skip to content

Fix callTool() crash on JSON-RPC error responses#9

Merged
frouaix merged 2 commits intoissue-1-e2e-testingfrom
copilot/sub-pr-7-again
Feb 22, 2026
Merged

Fix callTool() crash on JSON-RPC error responses#9
frouaix merged 2 commits intoissue-1-e2e-testingfrom
copilot/sub-pr-7-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 22, 2026

callTool() unconditionally accessed response["result"]["content"], throwing if the server returned a JSON-RPC error object (response["error"]) instead of a result — masking the real error and breaking test determinism.

Changes

  • e2e-apps.test.tscallTool() error handling: Added early-return branch for response["error"], returning a structured { isError: true, text, parsed, raw } instead of throwing:
if (response["error"]) {
  const err = response["error"] as Record<string, unknown>;
  const code = err["code"] != null ? ` (code: ${err["code"]})` : "";
  const text = String(err["message"] ?? JSON.stringify(err)) + code;
  return { raw: response, text, parsed: err, isError: true };
}

Both JSON-RPC-level errors and application-level isError results now surface consistently through the same isError signal.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: frouaix <876178+frouaix@users.noreply.github.com>
Copilot AI changed the title [WIP] Update E2E tests based on feedback from PR #1 Fix callTool() crash on JSON-RPC error responses Feb 22, 2026
Copilot AI requested a review from frouaix February 22, 2026 01:43
@frouaix frouaix marked this pull request as ready for review February 22, 2026 01:45
Copilot AI review requested due to automatic review settings February 22, 2026 01:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a crash in the callTool() test helper function when the MCP server returns a JSON-RPC error response. Previously, the function unconditionally accessed response["result"]["content"], which would throw if the server returned a JSON-RPC error object (response["error"]) instead. This masked the real error and broke test determinism.

Changes:

  • Added early-return error handling in callTool() to check for response["error"] before accessing response["result"]
  • Error responses are now returned with a structured { isError: true, text, parsed, raw } format, consistent with application-level errors
  • Both JSON-RPC protocol errors and application-level isError results surface consistently through the same isError signal

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@frouaix frouaix merged commit 1738665 into issue-1-e2e-testing Feb 22, 2026
4 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.

3 participants