Skip to main content

Input validation

When you define an input schema, each request is validated before executing the handler. If validation fails, the handler does not execute and a 400 is returned:

Example with full schema

index.ts

Supported types

You can use any Zod type inside z.object():

Coercion in GET requests

For GET requests, query parameters are strings. Use z.coerce to convert types automatically:
index.ts

.describe() annotations

Use .describe() on each field to document the parameters. These descriptions appear automatically in the MCP schema, which helps AI agents understand how to use your function:

Output validation

When you define an output schema, the value returned by the handler is validated after execution. If it does not match:
  • A warning is logged
  • The response is sent normally with status 200
Output validation never blocks the response. It is a development tool to detect inconsistencies.
If the handler returns { name: "Maria", balance: "150" } (balance as string), you will see a warning in the logs but the client receives the response unchanged.

Validation error format

Each error in the details array contains: