Skip to content

DurableAgent rejects MCP dynamic tools that have no validate function on inputSchema #1576

Open

Description

@softmarshmallow

Bug

DurableAgent.executeTool() in @workflow/ai@4.1.0-beta.59 incorrectly rejects tool calls for MCP dynamic tools whose inputSchema (created via jsonSchema() from @ai-sdk/provider-utils) has no validate function.

Reproduction

Use @ai-sdk/mcp to create MCP tools (which produces dynamicTool with jsonSchema() wrapper — no validate fn), then pass them to a DurableAgent. When the model calls any of these tools, the agent throws:

Error: Invalid input for tool "toolName": undefined

Root cause

In durable-agent.js L677–693:

const input = await schema.validate?.(JSON.parse(toolCall.input || '{}'));
if (!input?.success) {
    throw new Error(`Invalid input for tool "${toolCall.toolName}": ${input?.error?.message}`);
}
  1. schema.validate is undefined for MCP dynamic tools (the jsonSchema() helper from @ai-sdk/provider-utils does not set a validate function)
  2. schema.validate?.() returns undefined via optional chaining
  3. !undefined?.success → !undefined → true — enters the error branch
  4. undefined?.error?.message → undefined — produces the ": undefined" suffix

The AI SDK's own safeValidateTypes handles this correctly by short-circuiting:

if (actualSchema.validate == null) {
    return { success: true, value, rawValue: value };
}

Suggested fix

Add a nullish guard before the validation check:

const input = await schema.validate?.(JSON.parse(toolCall.input || '{}'));
if (input !== undefined && !input.success) {
    // validation ran and failed
    throw new Error(...);
}
parsedInput = input?.value ?? JSON.parse(toolCall.input || '{}');

Or, match the AI SDK pattern:

const parsed = JSON.parse(toolCall.input || '{}');
if (typeof schema.validate === 'function') {
    const input = await schema.validate(parsed);
    if (!input.success) {
        throw new Error(`Invalid input for tool "${toolCall.toolName}": ${input.error?.message}`);
    }
    parsedInput = input.value;
} else {
    parsedInput = parsed;
}

Environment

  • @workflow/ai: 4.1.0-beta.59
  • ai: 6.0.142
  • @ai-sdk/mcp: 1.0.30
  • @ai-sdk/provider-utils: 4.0.21
  • @modelcontextprotocol/sdk: 1.29.0

Workaround

Patch a passthrough validate onto MCP tool schemas before passing them to DurableAgent:

if (schema && typeof schema.validate !== "function") {
    schema.validate = (value: unknown) => ({ success: true, value });
}

Activity

  1. wasimxyz commented on Jun 22, 2026

    @wasimxyz

    Still reproduces on @workflow/ai@^6.0.0 (with ai@6.0.175, @ai-sdk/mcp@^1.0.42). Every MCP tool call surfaced via @ai-sdk/mcp fails before executing with:

    Error: Invalid input for tool "notion__notion_search": undefined
    

    Looks like this issue was mentioned in #12165 which ships a new WorkflowAgent. I guess DurableAgent won't be patched?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions