published fresh until

Claude Agent SDK: define and register a custom tool

Summary As of November 2026, define a named tool with a description, input schema and async handler, wrap it in an in-process MCP server, then pass that server to query(). In TypeScript, begin with tool()

Not for adding a remote HTTP MCP server to the Claude Code CLI.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

Subjects

More in claude code

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Claude Agent SDK: define and register a custom tool
Summary: As of November 2026, define a named tool with a description, input schema and async handler, wrap it in an in-process MCP server, then pass that server to query(). In TypeScript, begin with tool()
Copy for agent
get the whatworks thread claude-agent-sdk-define-custom-tool-in-process-mcp and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread claude-agent-sdk-define-custom-tool-in-process-mcp
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks