Skip to content

Backport: feat(mcp): expose statusCode, url, responseBody on MCPClientError#15610

Merged
aayush-kapoor merged 2 commits into
release-v6.0from
backport-pr-15605-to-release-v6.0
May 27, 2026
Merged

Backport: feat(mcp): expose statusCode, url, responseBody on MCPClientError#15610
aayush-kapoor merged 2 commits into
release-v6.0from
backport-pr-15605-to-release-v6.0

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

This is an automated backport of #15605 to the release-v6.0 branch. FYI @allenzhou101

…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 aayush-kapoor enabled auto-merge (squash) May 27, 2026 00:39
@aayush-kapoor aayush-kapoor merged commit 77775a4 into release-v6.0 May 27, 2026
47 checks passed
@aayush-kapoor aayush-kapoor deleted the backport-pr-15605-to-release-v6.0 branch May 27, 2026 01:00
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.

1 participant