Overview
The@tool decorator creates tools that can be used with SDK MCP servers. Tools run in-process within your Python application, providing better performance than external MCP servers.
Signature
Parameters
Unique identifier for the tool. This is what Claude will use to reference the tool in function calls.
Human-readable description of what the tool does. This helps Claude understand when to use the tool.
Schema defining the tool’s input parameters. Can be either:
- A dictionary mapping parameter names to types (e.g.,
{"text": str}) - A TypedDict class for more complex schemas
- A JSON Schema dictionary for full validation
Optional MCP tool annotations for additional metadata.
Returns
A decorator function that wraps the tool implementation and returns anSdkMcpTool instance ready for use with create_sdk_mcp_server().
Examples
Basic Tool
Simple tool with a basic schema:Tool with Multiple Parameters
Tool that processes multiple inputs:Tool with Error Handling
Tool that handles errors gracefully:Tool Function Requirements
The tool function must follow these requirements:
- Must be async (defined with
async def) - Receives a single dict argument with the input parameters
- Should return a dict with a
"content"key containing the response - Errors can be indicated by including
"is_error": Truein the response
Return Format
Tool functions should return a dictionary with the following structure:Usage with SDK MCP Server
Tools created with the@tool decorator are used with create_sdk_mcp_server():
See Also
- create_sdk_mcp_server() - Create an in-process MCP server
- ClaudeAgentOptions - Configuration for using servers with query()