Declare Parameters with Type Hints
Use Python hints to shape the tool schema.
Declare Parameters with Type Hints is a free MCP Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MCP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Parameters Become a Schema
Every argument of your tool function turns into part of an input schema the model must follow when it calls your tool. 🧩
Type Hints Do the Work
FastMCP reads your Python type hints and builds the JSON schema for you, so you rarely write schema by hand.
@mcp.tool()
def add(a: int, b: int) -> int:
return a + bstr, int, float, bool
The basic types map cleanly: str becomes string, int and float become number, and bool becomes boolean in the schema.
Untyped Means Unclear
Skip the type hint and the model only sees a loose value with no rules, which invites wrong or invalid input.
def add(a, b):
return a + bRequired by Default
A parameter with no default value is treated as required, so the model must always supply it when calling the tool.
Defaults Make It Optional
Give a parameter a default and it becomes optional. The model may omit it, and your function uses the fallback value.
@mcp.tool()
def greet(name: str, formal: bool = False) -> str:
...Lists and Dicts
You can hint collections too. A list argument maps to a JSON array, and a dict maps to an object the model can fill in.
def tag(items: list[str]) -> int:
return len(items)Optional Values
Use Optional when an argument may be a value or None, signaling that the model can leave it empty on purpose.
from typing import Optional
def find(q: str, limit: Optional[int] = None):
...Name Parameters Clearly
The model sees each parameter name in the schema, so city beats c and start_date beats arg2. Clear names guide better calls.
Hints Power Validation
Because hints define the schema, MCP can reject calls with the wrong type before your code runs, catching mistakes early.
Keep the Signature Small
Fewer, well-typed parameters are easier for the model to fill correctly than a long list of loosely related arguments.
Quick Check
What makes a tool parameter optional in FastMCP?
Recap
Your type hints build the tool schema: basic types map directly, defaults mean optional, and clear names guide the model. ✅
Frequently asked questions
Is the “Declare Parameters with Type Hints” lesson free?
Yes — the full text of “Declare Parameters with Type Hints” is free to read here on the web, and the MCP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MCP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Declare Parameters with Type Hints”?
Use Python hints to shape the tool schema. You practise MCP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MCP Academy?
No prior experience is required. MCP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Declare Parameters with Type Hints” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MCP Academy lesson?
Yes. Every MCP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Name & Describe a Tool Well
- Declare Parameters with Type Hints
- Return Useful Results
- A Calculator Tool, Start to Finish