What this thread does
Do first: define your TypeScript tool with tool() or your Python tool with @tool, supplying a name, description, input schema and async handler.
When you need it
Custom tools let an SDK agent call application functions for domain-specific operations. The SDK's MCP server runs inside your application process.
Steps
1. Use the page's weather example as the complete definition. Its TypeScript imports are:
import { tool, createSdkMcpServer } from "@anthropic-ai/claude-agent-sdk";
import { z } from "zod";
The get_temperature tool takes latitude and longitude as Zod number fields. Its async handler receives the validated arguments and returns content, an array of result blocks. Text result blocks use type: "text" and text. Python uses a dict schema and @tool instead. 2. Wrap the example's getTemperature function in an in-process server:
const weatherServer = createSdkMcpServer({
name: "weather",
version: "1.0.0",
tools: [getTemperature]
});
3. Pass the server through mcpServers in query() options and pre-approve the fully qualified tool name with allowedTools:
mcpServers: { weather: weatherServer },
allowedTools: ["mcp__weather__get_temperature"]
The name follows mcp__{server_name}__{tool_name}. The server component is the key in mcpServers; replace dots or spaces in that key with underscores when constructing the tool name. 4. Combine the page's complete weather tool, server and query() snippets in weather.ts, then use its TypeScript launch command:
npx tsx weather.ts
These extracts show configuration points; use the linked page's full weather handler and query loop for that runnable example.
Check it worked
The page says Claude calls get_temperature and the script prints a one-line temperature answer for San Francisco.
Limits
allowedTools controls permission, while tools controls built-in tool availability. tools: ["Read", "Grep"] removes other built-ins but leaves MCP tools unaffected; tools: [] removes all built-ins. Tools left out of allowedTools still go through the permission flow. In Python's dict schema every key is required; optional fields need the documented JSON Schema or typed-schema approach.
Not for: configuring a remote HTTP MCP server in the CLI; see claude-code-mcp-add-remote-http-server-header-auth-sse-deprecated.
Sources
- Give Claude custom tools, Anthropic documentation, read 2026-11-24: "A tool is defined by four parts, passed as arguments to the"
Checked
2026-11-24; read <https://code.claude.com/docs/en/agent-sdk/custom-tools#create-a-custom-tool> and <https://code.claude.com/docs/en/changelog> (top entry 2.1.331, November 23, 2026); no command was run. The documented procedure remains described as of this release.
Started from a post by @Anthropic, packaged by the editor. Original post