Skip to content

fix(runtime): surface API errors instead of returning them as successful results - #58

Merged
johnxie merged 1 commit into
mainfrom
fix/surface-api-errors
Jun 27, 2026
Merged

fix(runtime): surface API errors instead of returning them as successful results#58
johnxie merged 1 commit into
mainfrom
fix/surface-api-errors

Conversation

@johnxie

@johnxie johnxie commented Jun 27, 2026

Copy link
Copy Markdown
Member

Problem

The runtime did return await response.json() with no status check (runtime.ts:129). A non-2xx response (401/403/422/5xx) with a JSON body was returned as a successful CallToolResult — the model saw the error payload as a valid result. It's worst for promptAgent, whose normalizer literally appends "This is the agent's reply" — so an auth error gets relayed to the user as the agent's answer.

Fix (shared runtime → all 62 tools)

  • defaultExecuteToolCall: gate on response.ok; on a non-2xx read the body as text and throw with status + body.
  • executeToolCall: the catch now returns { isError: true, content: [...] } instead of rethrowing — covering both HTTP errors and network/transport failures with a clear, model-actionable message.
  • Fixed once in packages/openapi-codegen/src/runtime.ts; regenerated into tools.generated.ts + tools.v2.generated.ts.

Zero-regression evidence

  • The regenerated diff touches only the inlined runtime block0 per-tool server.tool() lines changed (verified). Tool counts hold: 57 v1 + 5 v2 = 62.
  • The 2xx path is unchanged; the 15 normalizeResponse handlers only run on 2xx, so none are affected.
  • Adds the first executeToolCall runtime tests (2xx / 401 / 500 / network failure). 17 tests pass, lint clean.

cc @deanzaka @lxcid

…ful results

The runtime returned `await response.json()` with no status check, so a non-2xx
response (401/403/422/5xx) was handed back as a successful tool result — the model saw
an error payload as if the call succeeded (worst for promptAgent, whose normalizer says
"this is the agent's reply"). Now: gate on `response.ok`, throw on non-2xx, and have
executeToolCall return an `isError` CallToolResult (also covering network failures).

- Fix in the shared packages/openapi-codegen/src/runtime.ts → regenerated into both
  tools.generated.ts and tools.v2.generated.ts (runtime block only; 0 per-tool changes).
- The 2xx path and all 15 normalizeResponse handlers are unchanged (they only run on 2xx).
- Adds runtime tests for 2xx / 401 / 500 / network-failure (17 tests pass). Benefits all 62 tools.
@johnxie
johnxie requested a review from Copilot June 27, 2026 09:57
@changeset-bot

changeset-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2771bb2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@taskade/mcp-server Patch
@taskade/mcp-openapi-codegen Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@johnxie
johnxie merged commit 34e978d into main Jun 27, 2026
1 of 2 checks passed
@johnxie
johnxie deleted the fix/surface-api-errors branch June 27, 2026 09:58
@github-actions github-actions Bot mentioned this pull request Jun 27, 2026
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.

2 participants