Skip to main content

Add custom tools

Tools let Claude call functions that execute in your application - query databases, call APIs, interact with UI elements, or perform any action your app needs.

How It Works

When you define a tool with a handler, the handler runs in your application (not on the server):
Your tools have access to everything in your app: databases, APIs, the DOM, local storage, etc. For type definitions, see SDK Types Reference.

JavaScript

Simple Object Syntax

McpServerBuilder

For multiple related tools, use the builder pattern:

Result Helpers


Python

Tool Decorator

The @tool decorator automatically infers the JSON schema from type hints:

With Pydantic Model

MCP Server

Type Mapping


Input Schema

Use JSON Schema to define parameters:

Tool Results

Handlers return a ToolResult object:

Browser Tools

In the browser, tools have access to the DOM:

Best Practices

Claude uses descriptions to decide when to use tools:
Return informative errors so Claude can respond appropriately:
Each tool should do one thing well: