Skip to content

docs: fix outdated APIs and broken MCP example in cookbook#14772

Open
omarrns wants to merge 1 commit intovercel:mainfrom
omarrns:fix/cookbook-mcp-stale-apis
Open

docs: fix outdated APIs and broken MCP example in cookbook#14772
omarrns wants to merge 1 commit intovercel:mainfrom
omarrns:fix/cookbook-mcp-stale-apis

Conversation

@omarrns
Copy link
Copy Markdown

@omarrns omarrns commented Apr 28, 2026

Summary

Three small but real bugs in content/, all confirmed against current main:

  1. content/cookbook/01-next/73-mcp-tools.mdx — calls response.toDataStreamResponse(), which was renamed to toUIMessageStreamResponse() in v5 and no longer exists on StreamTextResult (packages/ai/src/generate-text/stream-text-result.ts:359). Copy-pasting the cookbook into a Next route handler produces a TypeError at runtime.

  2. content/cookbook/05-node/54-mcp-tools.mdx — variable shadowing bug. The example declares let clientOne / clientTwo / clientThree outside the try, then re-declares each as const inside. The inner const shadows the outer let, so the outer bindings stay undefined. The finally block then calls clientOne.close() on undefined and the process always crashes — even on the happy path, and before any actual cleanup runs.

    Fix: drop the inner const keywords so the outer bindings get assigned, type them as MCPClient | undefined (MCPClient is a stable export from @ai-sdk/mcp), and use optional chaining in finally so partial-init failures still clean up clients that did connect.

  3. content/docs/09-troubleshooting/12-use-chat-an-error-occurred.mdx — three pre-v5 API names: toDataStreamResponse, getErrorMessage:, and createDataStreamResponse. Per the v5 migration guide (content/docs/08-migration-guides/26-migration-guide-5-0.mdx, §"Error Handling: getErrorMessage → onError"), these are now toUIMessageStreamResponse, onError:, and the split createUIMessageStream + createUIMessageStreamResponse pair. The doc was already internally inconsistent — line 44 used the new toUIMessageStreamResponse but still passed the old getErrorMessage: option to it.

Docs-only, no package changes, no changeset (matches the precedent of #12097 "docs: fix incorrect and outdated cookbooks").

Test plan

  • Maintainer review of the three diffs
  • Confirm MCPClient is the right stable type to expose in the cookbook (vs. inferring via Awaited<ReturnType<typeof createMCPClient>>)
  • Confirm the v5+ replacement names match the maintainers' preferred naming in cookbook copy

Three small but real bugs in the docs/cookbook content:

1. content/cookbook/01-next/73-mcp-tools.mdx
   `streamText().toDataStreamResponse()` was renamed to
   `toUIMessageStreamResponse()` in v5 and the old method no longer
   exists on `StreamTextResult`. Following the cookbook copy-paste
   produces a TypeError at runtime.

2. content/cookbook/05-node/54-mcp-tools.mdx
   The example declares `let clientOne / clientTwo / clientThree`
   outside the `try`, then re-declares them as `const` inside the
   `try`. The inner `const` shadows the outer `let`, so the outer
   bindings stay `undefined`. The `finally` block then calls
   `clientOne.close()` on `undefined` and the process always crashes
   - even on the happy path, and even before any cleanup runs.

   Removed the inner `const` keywords so the outer bindings get
   assigned, typed them as `MCPClient | undefined`, and used optional
   chaining in `finally` so a partially-initialized run still cleans
   up the clients that did connect.

3. content/docs/09-troubleshooting/12-use-chat-an-error-occurred.mdx
   References to `toDataStreamResponse`, `getErrorMessage`, and
   `createDataStreamResponse` are all pre-v5 names. Per the v5
   migration guide they're now `toUIMessageStreamResponse`, `onError`,
   and `createUIMessageStream` + `createUIMessageStreamResponse`.
   Note: the doc was already internally inconsistent — line 44 used
   the new `toUIMessageStreamResponse` but still passed the old
   `getErrorMessage:` option to it. Updated the prose and both
   snippets to the current API.
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