createMCPServer from @tanstack/ai-mcp/server checks a tool's input against the JSON Schema it derives from the tool's inputSchema, then calls the tool with the raw arguments. The tool's own schema never runs, so a Zod transform or default has no effect: .trim() keeps the spaces, .trim().min(1) accepts a blank string, and .default(false) leaves the field out.
chat() behaves differently: executeServerTool calls validateToolInput(tool.inputSchema, args, tool.name) and passes the parsed value to the tool. The same tool definition therefore gets different input under chat() and under createMCPServer.
Reproduce#
@tanstack/ai 1.7.0, @tanstack/ai-mcp 1.3.0, zod 4.6.7:
import { toolDefinition } from "@tanstack/ai"
import { createMCPServer } from "@tanstack/ai-mcp/server"
import { z } from "zod"
const t = toolDefinition({
name: "t",
description: "t",
inputSchema: z.object({ title: z.string().trim().min(1), flag: z.boolean().default(false) }),
}).server((input) => ({ content: [{ type: "text", text: JSON.stringify(input) }] }))
const server = createMCPServer({ name: "x", version: "1", tools: [t] })
for (const args of [{ title: " padded " }, { title: " " }]) {
const body = JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "t", arguments: args } })
const response = await server.handle(new Request("https://x.test/mcp", {
method: "POST",
headers: { "content-type": "application/json", accept: "application/json, text/event-stream" },
body,
}))
console.log(await response.text())
}
Observed: the tool gets {"title":" padded "} and {"title":" "}. Neither call is refused, and flag is missing.
Expected: as under chat(), the tool gets {"title":"padded","flag":false}, and the blank title fails validation with an isError result.
Where#
In dist/esm/server/create-server.js, standardSchema() converts the schema with convertSchemaToJsonSchema and fromJsonSchema, so the SDK's validateToolInput checks JSON Schema only. runTool then calls tool.execute(args ?? {}, ctx) with the SDK's result, which is the raw input.
The TypeScript types also show the input type before transforms. For example, a .default(false) field is typed boolean | undefined in .server().