pydantic-mcp
pydantic-mcp is an MCP server for inspecting, validating, and working with Pydantic models and Python type contracts in LLM workflows, providing deterministic validation, serialization, schema generation, and migration assistance.
Discover Models: Scan configured packages to find exported Pydantic
BaseModelclasses, with optional filtering and package selection.Inspect & Explain Types: Resolve any Python type annotation or model into a structured description, and generate human-readable documentation covering fields, defaults, aliases, constraints, and nested structures.
Validate Data: Validate arbitrary payloads against a model or Python type expression, with support for strict mode, Python/JSON mode, and validation context.
Serialize Data: Dump validated data using Pydantic serialization, with options for aliases, excluding unset/none/default values, round-trip mode, and Python/JSON output.
Generate JSON Schema: Produce validation or serialization JSON Schema for any model or type, with optional
$defsdefinitions.Create Example Payloads: Generate valid (and optionally invalid) example payloads for a target model or type.
Compare Validation Modes: Contrast model vs. TypeAdapter, strict vs. non-strict, and Python vs. JSON validation behavior for the same data.
Migrate v1 to v2: Analyze code snippets or model sources for common Pydantic v1-to-v2 migration issues, with optional auto-fix suggestions.
Parse Partial JSON: Best-effort parse incomplete JSON strings and validate the resulting fragment against a target type.
Generate Model from JSON: Infer and generate candidate Pydantic model definitions from a sample JSON payload.
MCP Integration: Expose tools, resources, and prompts via the MCP protocol, with HTTP health and readiness endpoints for server monitoring.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@pydantic-mcpGenerate a JSON schema for the UserProfile model"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
pydantic-mcp
pydantic-mcp is an MCP server for inspecting Pydantic models and Python type contracts. It is built for LLM workflows that need deterministic validation, serialization, schema generation, model explanations, and migration help.
Features
Discover Pydantic
BaseModelclasses across configured packages.Resolve targets from import paths, short model names, Python type expressions, or inline model snippets.
Validate arbitrary payloads with
TypeAdapteror model behavior.Serialize validated data in Python or JSON mode.
Generate validation and serialization JSON Schema.
Explain fields, defaults, aliases, decorators, constraints, and nested models.
Generate valid and invalid example payloads.
Infer candidate Pydantic models from sample JSON payloads.
Compare strict/non-strict and Python-vs-JSON validation behavior.
Analyze common Pydantic v1 to v2 migration issues.
Parse partial JSON with
pydantic_core.from_json.Expose MCP tools, resources, prompts, plus HTTP health/readiness routes.
Tools
list_modelsinspect_typeexplain_modelvalidate_dataserialize_datagenerate_json_schemacreate_example_payloadgenerate_model_from_jsoncompare_validation_modesmigrate_v1_to_v2parse_partial_json
Resources
pydantic://server/capabilitiespydantic://project/settingspydantic://project/import-rootspydantic://project/errors/recentpydantic://project/models/changedpydantic://models/indexpydantic://models/{qualified_name}pydantic://schemas/{qualified_name}?mode=validation|serializationpydantic://examples/{qualified_name}pydantic://migration/rulespydantic://reference/overview
Prompts
explain modelgenerate api contract docsdebug validation errordesign a model from example jsonreview schema compatibilitymigrate to pydantic v2
Run
Install dependencies:
uv syncRun over stdio:
uv run python mcp_server.py --transport stdioRun over HTTP:
uv run python mcp_server.py --transport http --host 127.0.0.1 --port 8000Health endpoints:
GET /healthzGET /readyz
Configuration
Important environment variables:
PYDANTIC_MCP_ALLOWED_IMPORT_ROOTSPYDANTIC_MCP_DEFAULT_SCAN_PACKAGESPYDANTIC_MCP_IMPORT_TIMEOUT_SECONDSPYDANTIC_MCP_ERROR_HISTORY_LIMITPYDANTIC_MCP_TRANSPORTPYDANTIC_MCP_HOSTPYDANTIC_MCP_PORT
Example:
PYDANTIC_MCP_ALLOWED_IMPORT_ROOTS=your_app.models \
PYDANTIC_MCP_DEFAULT_SCAN_PACKAGES=your_app.models \
uv run python mcp_server.py --transport stdioThese values must point at importable application packages in the runtime environment. For local smoke tests, the repository ships an installable sample package at pydantic_mcp_sample_app, but production deployments should point at your own application modules.
Testing
just testResources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/BitingSnakes/pydantic-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server