feat(mcp): allow custom fetch for HTTP and SSE transports#14134
Merged
aayush-kapoor merged 5 commits intoApr 6, 2026
Conversation
Adds an optional `fetch` option to `MCPTransportConfig` (and both `HttpMCPTransport` / `SseMCPTransport` constructors) so callers can supply a request-local fetch instead of relying on `globalThis.fetch`. The custom fetch is also forwarded to OAuth `auth()` calls so token discovery and exchange use the same fetch implementation. Fixes runtimes where self-fetches are blocked (e.g. Cloudflare Workers error 1042 on same-worker MCP routes with Nitro). Closes vercel#13449
aayush-kapoor
approved these changes
Apr 6, 2026
ghost
pushed a commit
that referenced
this pull request
Apr 6, 2026
|
|
|
🚀 Published in:
|
aayush-kapoor
added a commit
that referenced
this pull request
Apr 6, 2026
…14159) This is an automated backport of #14134 to the release-v6.0 branch. FYI @jaydeep-pipaliya This backport has conflicts that need to be resolved manually. ### `git cherry-pick` output ``` Auto-merging packages/mcp/src/tool/mcp-http-transport.test.ts Auto-merging packages/mcp/src/tool/mcp-http-transport.ts CONFLICT (content): Merge conflict in packages/mcp/src/tool/mcp-http-transport.ts Auto-merging packages/mcp/src/tool/mcp-sse-transport.test.ts Auto-merging packages/mcp/src/tool/mcp-sse-transport.ts CONFLICT (content): Merge conflict in packages/mcp/src/tool/mcp-sse-transport.ts Auto-merging packages/mcp/src/tool/mcp-transport.ts error: could not apply a00d1d3... feat(mcp): allow custom fetch for HTTP and SSE transports (#14134) hint: After resolving the conflicts, mark them with hint: "git add/rm <pathspec>", then run hint: "git cherry-pick --continue". hint: You can instead skip this commit with "git cherry-pick --skip". hint: To abort and get back to the state before "git cherry-pick", hint: run "git cherry-pick --abort". hint: Disable this message with "git config set advice.mergeConflict false" ``` --------- Co-authored-by: Jaydeep pipaliya <71074587+jaydeep-pipaliya@users.noreply.github.com> Co-authored-by: Aayush Kapoor <aayushkapoor34@gmail.com>
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.
Summary
Fixes #13449.
@ai-sdk/mcphardcodedglobalThis.fetchin its HTTP and SSE transports, breaking same-app MCP calls on runtimes that block self-fetches (e.g. Cloudflare Workers error1042via Nitro).fetchfield toMCPTransportConfigand bothHttpMCPTransport/SseMCPTransportconstructorsglobalThis.fetchwhen not provided (no breaking change)auth()calls so token discovery/exchange uses the same fetch implementationhttpandssetransport types as requested in the issueUsage:
Test plan
describe('custom fetch', ...)tests to bothmcp-http-transport.test.tsandmcp-sse-transport.test.tsverifying the custom fetch function is called for GET (start) and POST (send) operationspnpm test:node)pnpm buildinpackages/mcp)