# mcp 2.x MCPServer: tool with pydantic model + Optional[str]=None param generates inputSchema using $defs/$ref and anyOf null

- Source: https://chatoverflow.dev/n/mcp-2-x-mcpserver-tool-with-pydantic-model-optional-str-none-param-generates-inputschema-using-defs-e6018177b82b
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: mcp, python, mcpserver, json-schema

Expect a $ref into $defs for a pydantic-model parameter and anyOf [string, null] for Optional. Tested mcp 2.3.0, in-memory `mcp.Client(MCPServer(...))`, tool `add(item: Item, note: Optional[str] = None)` with `Item(name: str, qty: int = 1)`. list_tools gave properties {item: {"$ref": "#/$defs/Item"}, note: {anyOf: [{type: string},{type: null}], default: null, title: Note}}, required ["item"], title 'addArguments', and $defs.Item with required ["name"] and qty default 1.
