Claude API · Tool Use

Connect Claude to Any API or Database with Tool Use

Give Claude access to your APIs, databases, and systems.

Tool use (also called function calling) is how you connect Claude to the real world. Instead of answering from training data, Claude can query live APIs, read databases, trigger workflows, and interact with external services — all while deciding autonomously when a tool is needed and what to pass it.

Claude tool use (function calling) lets Claude interact with external APIs, databases, and services during a conversation. You define tools as JSON schemas, and Claude decides when to call them based on the user's request. This is the foundation of building AI agents that take real actions.

How It Works

The tool use loop, step by step

01

Define the tool

You describe a function — its name, what it does, and what parameters it accepts — as a JSON schema. Claude reads this definition and understands when to call it.

{
  "name": "get_weather",
  "description": "Get current weather for a city",
  "input_schema": {
    "type": "object",
    "properties": {
      "city": { "type": "string" },
      "units": { "type": "string", "enum": ["celsius","fahrenheit"] }
    },
    "required": ["city"]
  }
}
02

Claude decides when to call it

Based on the user's message and the tool description, Claude determines whether to call the tool, which parameters to pass, and — critically — whether a tool call is even necessary.

# User: "What's the weather in Tokyo right now?"
# Claude decides: tool call needed

tool_use = {
  "type": "tool_use",
  "name": "get_weather",
  "input": { "city": "Tokyo", "units": "celsius" }
}
03

You execute and return results

Your application runs the actual function — calls the API, queries the database, whatever it is — and returns the result to Claude as a tool_result message.

# Your app runs the real function
result = weather_api.get("Tokyo")

# Return result to Claude
tool_result = {
  "type": "tool_result",
  "tool_use_id": tool_use["id"],
  "content": json.dumps(result)
}
04

Claude synthesizes the response

Claude reads the tool result and formulates a natural language response for the user. It can make multiple tool calls in sequence, chain outputs, and handle errors gracefully.

# Claude responds with real data
"Tokyo is currently 22°C with partly cloudy
skies. Humidity is at 65%. Good conditions
for outdoor activities today."

Design Patterns

6 tool use patterns for production

Single tool, direct lookup
The simplest pattern. One tool, one call, one response. Ideal for weather lookups, database queries, or API fetches where you need a single piece of data to answer a question.
Parallel tool calls
Claude can call multiple tools in a single turn — simultaneously if they are independent. Fetch user data, check inventory, and query pricing all in one round trip before composing the answer.
Chained / sequential tool calls
The output of one tool feeds into the next. Claude searches for a product, reads the result, then calls a second tool to check stock at the nearest warehouse — no manual orchestration required.
Agentic loops
In agentic mode, Claude continues calling tools until it has everything needed to complete a task. It handles intermediate failures, adjusts its strategy, and reports back only when done.
Forced tool use
You can set tool_choice to force Claude to call a specific tool regardless of context. Useful for structured data extraction — guaranteed JSON output every time, no free-text fallback.
Computer use tools
Claude's computer use capability exposes a special set of tools: screenshot, click, type, scroll. Claude can operate desktop applications and browsers autonomously using this pattern.

Production best practices

Write descriptions like documentation

Claude decides whether to call a tool based entirely on its description. Write it as if documenting a function for another developer — be specific about what it returns, when to use it, and what the parameters mean.

Return structured data, not prose

Tool results should be machine-readable (JSON) rather than natural language. Claude is better at synthesizing structured data into a coherent response than parsing free-text tool outputs.

Handle tool errors explicitly

Return errors as tool_result with is_error: true. Claude will read the error message and decide whether to retry with different parameters, try another tool, or explain the issue to the user.

Limit tool count per request

More tools means more tokens in the context window and more opportunity for Claude to choose incorrectly. Pass only the tools relevant to the current task. Use dynamic tool selection at the application layer.

Validate and sanitize tool inputs

Even though Claude generates tool inputs, treat them as untrusted data at the execution layer. Validate parameter types, check bounds, and never execute raw SQL from a tool_use input without sanitization.

Frequently Asked Questions

What is Claude tool use?

Claude tool use (function calling) lets Claude interact with external APIs, databases, and services during a conversation. You define tools as JSON schemas and Claude decides when to call them based on the user's request.

Is Claude tool use the same as MCP?

Tool use and MCP are related but different. Tool use is the API-level capability for function calling. MCP (Model Context Protocol) is a standardized protocol for connecting Claude to external data sources and tools via a server interface.

What can I build with Claude tool use?

You can build AI agents that search databases, call APIs, process files, send emails, manage calendars, and take any programmable action. Tool use is the foundation of agentic Claude workflows.

How many tools can Claude use at once?

Claude can handle dozens of tool definitions in a single request. It selects the appropriate tool based on the user's intent and can chain multiple tool calls sequentially to complete multi-step tasks.

Build your first tool-using agent

The API tutorial walks you through the full loop.