Input validation
When you define aninput 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 insidez.object():
Coercion in GET requests
For GET requests, query parameters are strings. Usez.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 anoutput 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.
{ 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 thedetails array contains:
| Field | Type | Description |
|---|---|---|
path | string[] | Path to the field with the error, e.g.: ["email"] or ["address", "city"] |
message | string | Human-readable error message |
code | string | Zod error code (e.g.: invalid_string, too_small, invalid_enum_value) |