High severity intermediate · Fix: 5-10 min

ValidationError

pydantic.error_wrappers.ValidationError

What this error means
MCP tool call failed because the arguments passed do not conform to the expected Pydantic schema for that tool.

Stack trace

traceback
pydantic.error_wrappers.ValidationError: 1 validation error for ToolCallArgs
field_name
  field required (type=value_error.missing)

During handling of the above exception, MCP raised a schema validation error for the tool call arguments.
QUICK FIX
Validate and align your tool call argument dictionary exactly with the tool's Pydantic schema before invoking the tool.

Why it happens

MCP uses Pydantic models to validate the arguments passed to tools. If the arguments are missing required fields, have incorrect types, or extra unexpected fields, Pydantic raises a ValidationError. This usually happens when the input dictionary keys or types do not match the tool's argument schema exactly.

Detection

Catch pydantic.error_wrappers.ValidationError exceptions around tool call invocations and log the invalid argument payload to identify mismatches before the app crashes.

Causes & fixes

1

Missing required argument fields in the tool call dictionary

✓ Fix

Ensure all required fields defined in the tool's Pydantic argument schema are present in the dictionary passed to the tool call.

2

Argument fields have incorrect data types (e.g., string instead of int)

✓ Fix

Convert or cast argument values to the correct types as defined in the tool's Pydantic schema before calling the tool.

3

Extra unexpected fields included in the argument dictionary

✓ Fix

Remove any fields not defined in the tool's argument schema to avoid validation errors.

4

Using outdated or mismatched tool argument schema versions

✓ Fix

Update your MCP package and ensure your argument dictionaries match the latest schema definitions exactly.

Code: broken vs fixed

Broken - triggers the error
python
from mcp import MCP

mcp = MCP()
args = {'name': 'example'}  # Missing required fields
result = mcp.call_tool('my_tool', args)  # Raises ValidationError here
Fixed - works correctly
python
import os
from mcp import MCP

os.environ['MCP_API_KEY'] = os.environ.get('MCP_API_KEY', 'your_api_key_here')  # Use env var for keys

mcp = MCP()
args = {'name': 'example', 'count': 5}  # All required fields present with correct types
result = mcp.call_tool('my_tool', args)  # Fixed: no ValidationError
print(result)
Added all required fields with correct types to the argument dictionary to satisfy the Pydantic schema validation.

Workaround

Wrap the tool call in try/except ValidationError, catch the exception, log the invalid arguments, and attempt to fix or sanitize the input before retrying.

Prevention

Use typed data classes or Pydantic models to construct tool call arguments programmatically, ensuring schema compliance before calling MCP tools.

Python 3.9+ · mcp >=0.1.0 · tested on 0.2.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.