# MCP argument validation

Refuse invalid tool calls before any service code runs.

AI agents construct tool arguments themselves and sometimes get them wrong - a missing field, a hallucinated one, a string where a number belongs. With validation on, an [MCP gateway](https://zato.io/docs/ai/mcp/index.html) checks every `tools/call` against the tool's input schema before the service runs, and refuses invalid calls with an error naming the offending field, which lets the agent correct itself and retry.

Validation is the **Validate input against each tool's schema** checkbox, in the **Gateway options** micro-form under **More options** on the wizard's step 02, **What do they receive?**, and in [enmasse](https://zato.io/docs/admin/enmasse-reference.html) it is the `validate_input` attribute. It runs after [authentication](https://zato.io/docs/ai/mcp/security.html) and session checks - an unauthenticated caller never gets as far as validation.

## Validation rules {#validation-rules}

The schema is the one `tools/list` advertises, generated from the service's declared input - there is nothing separate to write or keep in sync. Against it, the gateway verifies:

- The `arguments` element is a JSON object.
- Every required field is present.
- No field outside the schema is accepted.
- Every value has its declared type - `string`, `integer`, `number`, `boolean`, `array` or `object`. A boolean does not pass as an integer or a number, and a null never matches - an optional field is expressed by absence, not by null.
- Arrays with a declared element type have each element checked, and nested objects recurse with the full rules above.

What a service with no declared input accepts is described under [tool schemas](https://zato.io/docs/ai/mcp/tool-schemas.html).

## Error responses {#error-responses}

An invalid call is refused with JSON-RPC error `-32602` and a message that names the field with its full path:

```json
{
    "jsonrpc": "2.0",
    "id": 7,
    "error": {
        "code": -32602,
        "message": "Missing required parameter: `customer_id`"
    }
}
```

The messages are:

| Message | Cause |
| --- | --- |
| `Invalid arguments: expected an object` | The `arguments` element is not a JSON object |
| `` Missing required parameter: `path` `` | A required field is absent |
| `` Unknown parameter: `path` `` | A field outside the schema was sent |
| ``Invalid type for `path`: expected integer`` | A value has the wrong type - the path descends into nested objects and arrays, e.g. `customer.addresses[2].zip_code` |

With the [audit log](https://zato.io/docs/ai/mcp/audit-log.html) on, refused calls are recorded with an `error` outcome and the error message, so systematically failing agents are visible in the dashboard.

## See also {#see-also}

- [Tool schemas](https://zato.io/docs/ai/mcp/tool-schemas.html) - The generated schema that calls are checked against
- [Response controls](https://zato.io/docs/ai/mcp/response-controls.html) - Shaping applied to responses after the service runs
- [Audit log](https://zato.io/docs/ai/mcp/audit-log.html) - How refused calls are recorded
- [Tool selection](https://zato.io/docs/ai/examples/tool-selection.html) - An agent corrected by validation errors, end to end

## Learn more {#learn-more}

- [MCP tutorial](https://zato.io/tutorials/mcp/01.html) - Expose Python services as AI tools and connect Claude Code in minutes
- [AI Integrations overview](https://zato.io/docs/ai/) - Both directions of AI traffic in one platform, and where to start
- [MCP gateway reference](https://zato.io/docs/ai/mcp/) - Configuration, endpoint behavior and the governance controls
- [Tool schemas](https://zato.io/docs/ai/mcp/tool-schemas.html) - How a service's docstring and declared I/O become its tool definition
- [MCP gateway security](https://zato.io/docs/ai/mcp/security.html) - API keys, Basic Auth and bearer tokens for AI agents
- [MCP response controls](https://zato.io/docs/ai/mcp/response-controls.html) - PII removal, prompt-injection safeguards and token-denominated size caps
- [MCP audit log](https://zato.io/docs/ai/mcp/audit-log.html) - What each agent did, when and with what outcome - payloads never recorded
- [MCP alerts](https://zato.io/docs/ai/mcp/alerts.html) - Failing backends, agents stuck in a loop and gateways with too many tools
- [Cost and limits](https://zato.io/docs/ai/cost-and-limits.html) - Every setting that caps AI cost and traffic, with worked examples
- [GitOps for AI integrations](https://zato.io/docs/ai/enmasse.html) - LLM connections and MCP gateways as YAML in version control
- [AI examples](https://zato.io/docs/ai/examples/) - Complete, runnable scenarios - one real-world need per file
