MCP Academy · Lesson

Model Inputs with Pydantic

Define a typed shape for a tool's arguments.

A Model Per Input

To shape a tool's arguments, you write a Pydantic model: a small class where each attribute is one typed field of the input.

from pydantic import BaseModel

class SearchInput(BaseModel):
    query: str
    limit: int

Subclass BaseModel

Every input model inherits from BaseModel, which gives it parsing, validation, and JSON schema generation for free.

All lessons in this course

  1. Why Schemas Beat Loose Args
  2. Model Inputs with Pydantic
  3. Constraints, Defaults & Enums
  4. Field Descriptions That Guide the Model
← Back to MCP Academy