Skip to content

feat(cloudflare): Drop the legacy MCP SDK transport from chat routes - #1924

Merged
BYK merged 1 commit into
mainfrom
scttcper/drop-mcp-sdk-v1
Nov 4, 2026
Merged

BYK merged 1 commit into
mainfrom
scttcper/drop-mcp-sdk-v1

Conversation

@scttcper

@scttcper scttcper commented Nov 4, 2026

Copy link
Copy Markdown
Member

The web chat and metadata routes still imported the v1 @modelcontextprotocol/sdk just for StreamableHTTPClientTransport. #1731 removed v1 from mcp-core but the worker kept this one import, which pulls a second copy of the MCP spec schemas into the bundle and builds them on every isolate start. @ai-sdk/mcp already has a built-in http transport that takes a url and headers, so this uses that and drops the dependency (and the vitest ajv stub that only existed for the legacy SDK).

Before After
Worker bundle (wrangler, uncompressed) 5,110 KiB 4,991 KiB (-119 KiB)
zod schemas built at startup 10,526 9,488 (-1,038)
Startup CPU (wrangler check startup, local median) ~61 ms ~54 ms

Startup numbers are local workerd runs, production cpus are slower so the absolute ms will be higher there.

Why it's safe:

  • Only /api/chat and /api/metadata use this client. The /mcp endpoint agents connect to is unchanged.
  • The @ai-sdk/mcp client is the same, only the transport underneath it changed.
  • Ran the built worker locally and made real read-only tool calls against sentry.io (whoami, find_organizations, find_projects) through both the old and new transport. Same 72 tools listed, identical results for every call.
  • The chat route refreshes the token when the MCP connection 401s. The new transport's error includes HTTP 401, so that still triggers. The old one only matched when the response body happened to say "access token", so it also missed the "Token audience does not match resource server" case.

The web chat and metadata routes still imported the v1
`@modelcontextprotocol/sdk` just for `StreamableHTTPClientTransport`,
long after the server moved to SDK v2. That pulled a second copy of the
MCP spec schemas into the worker and built ~1,000 extra zod schemas on
every isolate start.

`@ai-sdk/mcp` already ships an http transport that takes a url and
headers, so use that and drop the dependency. Also removes the vitest
ajv stub, which only existed because the legacy SDK imported ajv.

Worker bundle drops ~119 KiB and local startup CPU goes from ~61ms to
~54ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 4, 2026 12:42am UTC

Request Review

@scttcper scttcper changed the title perf(cloudflare): Drop the legacy MCP SDK transport from chat routes feat(cloudflare): Drop the legacy MCP SDK transport from chat routes Nov 4, 2026
@scttcper
scttcper marked this pull request as ready for review November 4, 2026 00:53
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 4, 2026
@scttcper
scttcper requested a review from BYK November 4, 2026 00:54
@BYK
BYK merged commit b8c8ab5 into main Nov 4, 2026
44 checks passed
@BYK
BYK deleted the scttcper/drop-mcp-sdk-v1 branch November 4, 2026 14:38

This branch was previously deployed

1 inactive deployment
Preview — c75f4d9d Deployed Nov 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants