Skip to content

Conversation

@dcramer
Copy link
Member

@dcramer dcramer commented Jan 31, 2026

Upgrade to AI SDK 6.x to support MCP protocol version 2025-11-25.

This upgrade enables compatibility with agents@0.3.5+ which is required for the latest MCP protocol features.

Package Changes

Package Before After
ai ^4.3.16 ^6.0.64
agents ^0.2.23 ^0.3.6
@ai-sdk/anthropic ^1.2.12 ^3.0.33
@ai-sdk/openai ^1.3.22 ^3.0.23
@ai-sdk/react ^1.2.12 ^3.0.66
@ai-sdk/mcp (new) ^1.0.16
@modelcontextprotocol/sdk ^1.21.0 ^1.25.3

API Migrations

  • MCP client imports: experimental_createMCPClient moved from "ai" to "@ai-sdk/mcp"
  • Type rename: LanguageModelV1LanguageModel (now a union type)
  • Step control: maxSteps: NstopWhen: stepCountIs(N)
  • Tool API: parametersinputSchema, execute(params)execute(input, options)
  • Tool call capture: toolCall.argstoolCall.input

This branch includes a revert of #759 as the base, then applies the full AI SDK 6.x migration on top.

Upgrade to AI SDK 6.x to support MCP protocol version 2025-11-25.

Package changes:
- ai: ^4.3.16 → ^6.0.64
- agents: ^0.2.23 → ^0.3.6
- @ai-sdk/anthropic: ^1.2.12 → ^3.0.33
- @ai-sdk/openai: ^1.3.22 → ^3.0.23
- @ai-sdk/react: ^1.2.12 → ^3.0.66
- @ai-sdk/mcp: (new) ^1.0.16
- @modelcontextprotocol/sdk: ^1.21.0 → ^1.25.3

API migrations:
- MCP client imports: "ai" → "@ai-sdk/mcp"
- Type rename: LanguageModelV1 → LanguageModel
- generateText/streamText: maxSteps → stopWhen(stepCountIs(N))
- tool() API: parameters → inputSchema, execute(params) → execute(input)
- Tool call capture: toolCall.args → toolCall.input

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The AI SDK 6.x migration renamed toolCall.args to toolCall.input.
This was correctly updated in callEmbeddedAgent.ts but missed in
the test client's agent.ts, causing logTool to receive undefined
instead of the actual tool arguments.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Migrate the cloudflare chat UI to be compatible with AI SDK 5+/6.x:

**Client-side changes:**
- Replace `Message` type with `UIMessage` (requires `parts` array)
- Migrate `useChat` to new API:
  - Use `DefaultChatTransport` with `api` option
  - Manage input state manually (removed from hook)
  - `append` → `sendMessage`
  - `reload` → `regenerate`
  - `handleInputChange`/`handleSubmit` → manual handlers
- Update all components to use `UIMessage` type
- Import from `@ai-sdk/react` instead of `ai/react`

**Server-side changes:**
- `maxTokens` → `maxOutputTokens`
- `toDataStreamResponse` → `toUIMessageStreamResponse`

**Dependency fixes:**
- Add pnpm override for `@modelcontextprotocol/sdk: ^1.25.3` to fix
  version mismatch between direct dep (1.25.3) and `agents` package
  (1.25.2) which caused TypeScript type conflicts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Additional fixes for UIMessage type changes in AI SDK 5+/6.x:

- Remove `content` property usage (UIMessage always uses `parts` array)
- Replace `data` with `metadata` for custom message metadata
- Remove `createdAt` property (no longer in UIMessage interface)
- Update tool part handling to support AI SDK 6 format where tool
  type is `tool-${toolName}` with properties directly on the part
- Remove legacy content fallback in processMessages

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactored the isValidMessage callback to use early return pattern,
which fixes the TypeScript error where msg.parts was narrowed to
type 'never' in the else branch. Since UIMessage.parts is a required
property, the previous if/else structure was flagged by TypeScript
as having unreachable code.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Addresses Cursor Bugbot feedback:
1. Legacy tool-invocation parts from persisted messages (AI SDK 4/5 format)
   now render correctly instead of being silently ignored
2. Tool output conversion now properly handles MCP-format objects with
   content arrays, strings, and other objects - avoiding [object Object]

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Legacy AI SDK 4/5 tool-invocation parts have structure:
{ type: "tool-invocation", toolInvocation: {...} }

The previous fix incorrectly cast the entire part to ChatToolInvocation
instead of accessing part.toolInvocation. This caused undefined values
for toolName, toolCallId, args, state, and result.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dcramer dcramer marked this pull request as ready for review January 31, 2026 16:42
Added migration logic to convert persisted messages from AI SDK 4.x
format (using `content` string) to AI SDK 6 format (using `parts` array).
This prevents silent data loss when users upgrade, as their chat history
will be automatically migrated instead of being filtered out.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

…igration

1. Fixed state mapping for AI SDK 6 tool parts to correctly handle
   'partial-call' state during streaming, preventing message persistence
   failures and incorrect UI rendering.

2. Updated migration function to preserve metadata from both legacy
   'data' property and new 'metadata' property, preventing loss of
   custom properties like type, hasSlashCommands, simulateStreaming.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link

@sentry-warden sentry-warden bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing-guidelines

testing-guidelines: Found 2 issues (2 medium)


⏱ 433.7s · 2.1M in / 34.8k out · $4.38

return msg as UIMessage;
}

export function usePersistedChat(isAuthenticated: boolean) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 No tests for usePersistedChat hook entry point (high confidence)

The usePersistedChat hook is exported and used in the Chat component as a user entry point, but has no test coverage. Per guidelines, every entry point should have at least one basic test.


warden: testing-guidelines

}

// Migrate legacy messages (AI SDK 4.x format with `content`) to new format (with `parts`)
function migrateMessage(msg: LegacyMessage): UIMessage {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 No tests for migrateMessage migration function (high confidence)

The new migrateMessage function handles SDK version migration for persisted messages. This is a pure function with complex logic for converting legacy format to new format - ideal for unit testing to ensure migration correctness.


warden: testing-guidelines

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.

2 participants