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
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"]
}
}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" }
}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)
}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
Production best practices
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.
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.
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.
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.
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.