DurableAgent rejects MCP dynamic tools that have no validate function on inputSchema
@gr2m is already working on this.
Since Apr 8, 2026.
- Dominant language
- TypeScript
- Stars
- 2.4k
- Forks
- 365
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 169
Description
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
const input = await schema.validate?.(JSON.parse(toolCall.input || '{}'));
if (!input?.success) {
throw new Error(`Invalid input for tool "${toolCall.toolName}": ${input?.error?.message}`);
}
schema.validateisundefinedfor MCP dynamic tools (thejsonSchema()helper from@ai-sdk/provider-utilsdoes not set avalidatefunction)schema.validate?.()returnsundefinedvia optional chaining!undefined?.success→!undefined→true— enters the error branchundefined?.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.59ai: 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 });
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.