Backport: feat(mcp): expose statusCode, url, responseBody on MCPClientError#15610
Merged
Merged
Conversation
…5605) ## Summary Adds `statusCode`, `url`, and `responseBody` to `MCPClientError` so downstream consumers can branch on HTTP context structurally instead of regex-parsing the error message. All three fields are optional and unset for stdio transport / non-response failures (network errors, aborts), so this is fully backward compatible. Populated at the four HTTP throw sites in `mcp-http-transport.ts`: - POST `!response.ok` → `statusCode`, `url`, `responseBody` - POST `text/event-stream` missing body → `statusCode`, `url` - POST unexpected content-type → `statusCode`, `url` - GET SSE failure → `statusCode`, `url` ## Why The MCP spec requires clients using streamable HTTP transport to fall back to legacy SSE transport when the server returns `404` (or `405`) on the streamable HTTP endpoint. To implement that correctly, the caller needs the response status — but today `MCPClientError` only exposes the message string. ## Validation - `pnpm --filter @ai-sdk/mcp type-check` ✓ - `pnpm --filter @ai-sdk/mcp test:node` — 208 passed ✓ - `pnpm --filter @ai-sdk/mcp test:edge` — 208 passed ✓ - `pnpm --filter @ai-sdk/mcp build` ✓ - Added integration tests asserting `statusCode` / `url` / `responseBody` for 404 (POST, with the "does not support HTTP transport" message), 500 (POST, with body), and 503 (GET SSE failure).
aayush-kapoor
approved these changes
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an automated backport of #15605 to the release-v6.0 branch. FYI @allenzhou101