Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/ai-sdk/src/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
SharedV3Headers,
ProviderV3,
} from '@ai-sdk/provider';
import type { FlexibleSchema, ToolExecutionOptions } from 'ai';
import { asSchema, type Schema, type ToolExecutionOptions } from 'ai';
import { ApplicationFailure } from '@temporalio/common';
import type { McpClientFactories, McpClientFactory } from './mcp';

Expand Down Expand Up @@ -44,7 +44,7 @@ export type InvokeEmbeddingModelResult = EmbeddingModelV3Result;

export interface ListToolResult {
description?: string;
inputSchema: FlexibleSchema<unknown>;
inputSchema: Schema<unknown>;
}

export interface ListToolArgs {
Expand Down Expand Up @@ -100,13 +100,12 @@ function activitiesForName(name: string, mcpClientFactory: McpClientFactory): ob
const mcpClient = await mcpClientFactory(args.clientArgs);
try {
const tools = await mcpClient.tools();

return Object.fromEntries(
Object.entries(tools).map(([k, v]) => [
k,
{
description: v.description,
inputSchema: v.inputSchema,
inputSchema: asSchema(v.inputSchema),
},
])
);
Expand Down
12 changes: 9 additions & 3 deletions packages/ai-sdk/src/mcp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { jsonSchema, type ToolSet } from 'ai';
import type { JSONSchema7 } from '@ai-sdk/provider';
import type { ToolSet } from 'ai';
import type { experimental_MCPClient as MCPClient } from '@ai-sdk/mcp';
import * as workflow from '@temporalio/workflow';
import type { ActivityOptions } from '@temporalio/workflow';
Expand Down Expand Up @@ -39,6 +38,7 @@ export class TemporalMCPClient {

const listActivity = activities[this.options.name + '-listTools'];
const tools: Record<string, ListToolResult> = await listActivity!({ clientArgs: this.options.clientArgs });

return Object.fromEntries(
Object.entries(tools).map(([toolName, toolResult]) => [
toolName,
Expand All @@ -52,7 +52,13 @@ export class TemporalMCPClient {
const callActivity = activities[this.options.name + '-callTool']!;
return await callActivity({ name: toolName, input, options, clientArgs: this.options.clientArgs });
},
inputSchema: jsonSchema(toolResult.inputSchema as JSONSchema7),
inputSchema: {
...toolResult.inputSchema,
_type: undefined,
validate: undefined,
[Symbol.for('vercel.ai.schema')]: true,
[Symbol.for('vercel.ai.validator')]: true,
},
type: 'dynamic',
},
])
Expand Down
Loading