Skip to main content

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

name
str
required
Unique identifier for the tool. This is what Claude will use to reference the tool in function calls.
description
str
required
Human-readable description of what the tool does. This helps Claude understand when to use the tool.
input_schema
type | dict[str, Any]
required
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
annotations
ToolAnnotations | None
default:"None"
Optional MCP tool annotations for additional metadata.

Returns

A decorator function that wraps the tool implementation and returns an SdkMcpTool 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": True in 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