Merged
Conversation
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>
26f48ec to
72cd2af
Compare
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>
packages/mcp-cloudflare/src/client/components/chat/chat-message.tsx
Outdated
Show resolved
Hide resolved
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>
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>
packages/mcp-cloudflare/src/client/components/chat/chat-message.tsx
Outdated
Show resolved
Hide resolved
…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>
The AI SDK 6.x has two different message formats: - UIMessage (client/UI format) uses a `parts` array - ModelMessage (API format) uses a `content` property The chat endpoint was passing UIMessage[] directly to streamText(), which expects ModelMessage[]. Added convertToModelMessages() to properly convert the format before streaming. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
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.
…parts Two bug fixes: 1. useChat transport not re-initializing when endpoint mode changes: The useChat hook captures the initial transport and doesn't reset when the prop changes. Added effect to clear messages when mode switches, ensuring the new transport is used for subsequent messages. 2. isValidMessage not validating AI SDK 6.x tool format: AI SDK 6.x uses "tool-<toolname>" format (e.g., "tool-whoami") instead of "tool-invocation". Updated validation to filter out incomplete tool calls (input-streaming, input-available, approval-requested states) from persisted messages. Also consolidated the auth logout and mode change effects into one. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Legacy AI SDK 4.x tool-invocation parts have structure:
{ type: "tool-invocation", toolInvocation: { state, result, ... } }
The validation was incorrectly accessing state and result directly on
the part object instead of through the nested toolInvocation property.
This caused all legacy tool-invocation parts to pass validation
regardless of their actual state.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.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.
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
aiagents@ai-sdk/anthropic@ai-sdk/openai@ai-sdk/react@ai-sdk/mcp@modelcontextprotocol/sdkAPI Migrations
experimental_createMCPClientmoved from"ai"to"@ai-sdk/mcp"LanguageModelV1→LanguageModel(now a union type)maxSteps: N→stopWhen: stepCountIs(N)parameters→inputSchema,execute(params)→execute(input, options)toolCall.args→toolCall.inputThis branch includes a revert of #759 as the base, then applies the full AI SDK 6.x migration on top.