Example
Anatomy of a Tool
Here’s the JSON-RPC response that the example above produces when a client callstools/list:
Minimal Definition
At minimum, a tool only needs a function with type hints:Tool Options
The@server.tool() decorator accepts these options:
Tool Annotations
Tool annotations provide hints to clients about the tool’s behavior:Async Tools
Tools can be async for non-blocking I/O operations:Using Context
Access the MCP context for logging and progress reporting. Add aContext parameter - it’s automatically excluded from the tool’s input schema:
Parameter Types and JSON Schema
Every tool parameter becomes a property in the tool’sinputSchema. mcp-use uses Pydantic to generate JSON Schema 2020-12 from your Python type hints.
Type mapping
Required, optional, and nullable
How you declare a parameter determines whether it appears in therequired array:
Enum parameters with Literal
UseLiteral to restrict a parameter to a fixed set of values. MCP clients like the Inspector render these as dropdown selects:
{"type": "string", "enum": ["public", "private", "team"]} in the schema.
mcp-use automatically simplifies Pydantic’s nullable
anyOf schemas. Without this,
str | None would produce {"anyOf": [{"type": "string"}, {"type": "null"}]} which
breaks description rendering in the MCP Inspector and fails validation in some clients
like Google’s Gemini API. mcp-use collapses this into {"type": "string", "default": null}.