Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

Background

Issue #6739 reported a type mismatch between McpToolSet (from @ai-sdk/mcp) and ToolSet (from ai), preventing users from passing MCP tools directly to streamText/generateText without casting.

After investigation, the issue no longer reproduces in the current codebase—McpToolSet<'automatic'> is correctly assignable to ToolSet because Tool<unknown, CallToolResult> is assignable to Tool<any, any> in the union.

Summary

Added type tests to prevent regression:

  • Verifies McpToolSet<'automatic'> is assignable to ToolSet
  • Verifies individual McpToolBase<unknown> is compatible with ToolSet values
  • Verifies Tool<unknown, CallToolResult> is assignable to Tool<any, any>

The test file duplicates the ToolSet type definition to avoid circular dependencies between @ai-sdk/mcp and ai packages.

Manual Verification

// Verified these compile without error:
const mcpClient = await createMCPClient({ transport: { type: 'sse', url: '...' } });
const tools = await mcpClient.tools();
const toolset: ToolSet = tools;  // ✓ No cast needed
streamText({ model, tools, prompt: 'Hello' });  // ✓ No cast needed

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Closes #6739

Original prompt

This section details on the original issue you should resolve

<issue_title>Type mismatch: McpToolSet not assignable to ToolSet (FlexibleSchema vs FlexibleSchema)</issue_title>
<issue_description>## Description

When using experimental_createMCPClient from @ai-sdk/mcp and passing the tools to streamText, TypeScript reports a type error because McpToolSet is not assignable to ToolSet.

Reproduction

import { experimental_createMCPClient } from "@ai-sdk/mcp";
import { streamText, type ToolSet } from "ai";
import { openai } from "@ai-sdk/openai";

const mcpClient = await experimental_createMCPClient({
  transport: { type: 'http', url: 'http://localhost:3001/mcp' },
});

// ❌ Type error without cast
const tools = await mcpClient.tools();

const result = streamText({
  model: openai("gpt-4.1"),
  tools, // Error: Type 'McpToolSet' is not assignable to type 'ToolSet'
  prompt: "Hello",
});

Error Message

Type '{ [x: string]: { inputSchema: FlexibleSchema<unknown>; ... }' is not assignable to type 'ToolSet'.

Types of property 'inputSchema' are incompatible.
  Type 'FlexibleSchema<unknown>' is not assignable to type 'FlexibleSchema<never>'.
    Type '$ZodType<unknown, ...>' is not assignable to type 'StandardSchemaV1<unknown, never>'.
      Types of property 'value' are incompatible.
        Type 'unknown' is not assignable to type 'never'.

Root Cause

  • mcpClient.tools() returns McpToolSet with inputSchema: FlexibleSchema<unknown>
  • streamText expects ToolSet with inputSchema: FlexibleSchema<never>

The unknown vs never variance is the core issue. MCP tools have dynamic schemas (unknown at compile time), but ToolSet expects strict type inference.

Current Workaround

Cast the tools:

const tools = (await mcpClient.tools()) as ToolSet;

Expected Behavior

mcpClient.tools() should return a type compatible with streamText's tools parameter without requiring a cast.

Environment

  • ai: 6.0.0-beta.124
  • @ai-sdk/mcp: 0.0.11
  • @ai-sdk/react: 3.0.0-beta.124
  • TypeScript: 5.x</issue_description>

<agent_instructions>try to reproduce with the latest codebase and if this is still an issue, explore solutions</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@aayush-kapoor could you try upgrading the mcp package to the latest beta as well?

i somehow don't observe the type error. I'm assuming it's a redline type error? </comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: lgrammel <205036+lgrammel@users.noreply.github.com>
…tation

Co-authored-by: lgrammel <205036+lgrammel@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix type mismatch for McpToolSet assignment Add type tests for McpToolSet and ToolSet compatibility Dec 19, 2025
Copilot AI requested a review from lgrammel December 19, 2025 13:11
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.

Type mismatch: McpToolSet not assignable to ToolSet (FlexibleSchema<unknown> vs FlexibleSchema<never>)

2 participants