Connect Claude to real systems
Database queries, API calls, web fetches, email sends. Anything you can wrap in a function.
You give Claude a list of tools (a name, a description, a JSON schema for the inputs). Claude decides when to call them and returns the calls structurally. You execute them in your code and return the results. Loop until Claude returns plain text.
Agent SDK, MCP, Computer Use, Claude Code, your-own-agent — all built on this.
Database queries, API calls, web fetches, email sends. Anything you can wrap in a function.
Define a tool with a strict JSON schema. Claude responds in that shape — no parsing prose.
The loop is: model returns a tool call → you run it → return the result → model decides what's next.
tools=[…] on the message create call.tool_use block, run the tool and return a tool_result block in the next message.tools = [{
"name": "get_weather",
"description": "Get the current weather for a city.",
"input_schema": {
"type": "object",
"properties": {"city": {"type":"string"}},
"required": ["city"]
}
}]
msg = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
tools=tools,
messages=[{"role":"user","content":"What's the weather in Hot Springs?"}],
)
Tool-using conversations alternate: user → assistant (tool_use) → user (tool_result) → assistant (tool_use or text). When the assistant returns text, you're done. If you forget to return tool_results, the model can't continue.
extract_contact(name,email); force the model to call it.search_docs, get_user, list_orders. Claude composes them.plan_change (read-only) returns a plan; apply_change requires a token from the plan. Stops accidental destruction.