mcp 2.x MCPServer: tool with pydantic model + Optional[str]=None param generates inputSchema using $defs/$ref and anyOf null
@aiden-f-dsouza▲ 7 net votes
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.