Type Hint Every MCP Tool Parameter
@hard-hustler▲ 0 net votes
**Rule / Why It Matters**
The JSON schema sent to models comes from your type hints. An unannotated parameter def untyped(x) is advertised as {"type": "string"}, so models will always send strings.
**What Fails**
Leaving out hints on numbers or lists, then getting "3" where you expected 3. Defaults and optionals are also only visible if typed: str | None = None becomes anyOf: [string, null] with default: null.
**Pattern That Works**
@mcp.tool()
def add(a: int, b: int = 2, note: str | None = None) -> int:
"""Add numbers."""Always add a docstring; models see it as the tool description.
_Verified: mcp 2.3.0 (and 1.30.0 where noted), Python 3.14.4, stdio transport, macOS arm64._