Client Tools, Server Tools and Approval Gates: Who Runs the Tool, and Who Says Yes First
Your own tools run in your code and every tool_use needs a tool_result. Server tools like web search run at Anthropic and come back already answered. A refund harness shows both, plus an approval gate that asks a person first and still answers a decline.
What you will learn
- Tell a client tool (tool_use, you run it) from a server tool (server_tool_use, Anthropic runs it)
- Handle the three server-tool response shapes: end_turn, pause_turn and a mixed turn
- Put an approval gate in front of a risky tool and still answer a declined call
- Describe the order in which the Agent SDK decides whether a tool call may run
Before you start
- Claude tool use: tool_use and tool_result
- Basic Python
A customer writes: please refund order 1042. Before anything happens, two questions come up. Who runs the tool? And who says yes first?
This article answers both with a small refund harness: a client tool, a server tool, and an approval gate in front of the risky one.
A workshop, a supplier and the manager's key
- Your own workshop. You do the work yourself, see every step and hand back the finished job. That is a client tool.
- A supplier. They work in their own factory and send the product back done. You only read what arrives. That is a server tool.
- The manager's key. A small sale goes through. A big refund waits until the manager says yes. That is an approval gate.
Two kinds of tools
One detail catches people: Anthropic's schema tools, such as bash, text editor, memory and computer use, are still client tools. Anthropic defines the schema; your code runs them. The client loop itself is in Claude tool use: tool_use and tool_result.
tools.py: mark each tool auto or ask
"""Client tools run here. Server tools run at Anthropic."""
def lookup_order(args):
return {"order_id": args["order_id"], "paid": True}
def issue_refund(args):
return {"refund_id": "R-7001", "amount": args["amount"]}
CLIENT_TOOLS = {
"lookup_order": {"run": lookup_order, "approval": "auto"},
"issue_refund": {"run": issue_refund, "approval": "ask"},
}
SERVER_TOOLS = [
{"type": "web_search_20250305", "name": "web_search"},
]
lookup_order only reads, so it runs at once. issue_refund moves money, so it waits for a person. web_search is only declared; we never run it.
harness.py: dispatch every block
"""The harness: dispatches every block of a Claude response."""
import json
from approval import ask_person
from tools import CLIENT_TOOLS
def tool_result(uid, data, error=False):
block = {"type": "tool_result", "tool_use_id": uid,
"content": json.dumps(data)}
if error:
block["is_error"] = True
return block
def dispatch(response, answers):
results = []
for block in response["content"]:
if block["type"] == "server_tool_use":
print(f' SERVER {block["name"]} runs at Anthropic')
if block["type"] != "tool_use":
continue
uid = block["id"]
tool = CLIENT_TOOLS[block["name"]]
ask = tool["approval"] == "ask"
if ask and not ask_person(block, answers):
note = {"message": "The user declined this call"}
results.append(tool_result(uid, note, error=True))
continue
print(f' CLIENT {block["name"]} runs here')
output = tool["run"](block["input"])
results.append(tool_result(uid, output))
return results
A server_tool_use block is only noted. For a client tool marked ask, the person is asked first. If they say no, the harness still adds a tool_result, with is_error set and a short message.
The gate itself, in approval.py, shows the person exactly what will run and returns true only for yes:
def describe(block):
name, args = block["name"], block["input"]
return f"{name}({args})"
def ask_person(block, answers):
answer = answers.pop(0)
print(f" ASK {describe(block)} -> {answer}")
return answer == "yes"
Run it: five scripted turns
agent_run.py uses a stand-in model that sends five scripted turns, and scripted answers from the person (yes, then no), so no API key is needed:
turn 1 stop_reason: tool_use
CLIENT lookup_order runs here
SEND 1 tool_result back, 0 is_error
turn 2 stop_reason: tool_use
ASK issue_refund({'order_id': '1042', 'amount': 49.9}) -> yes
CLIENT issue_refund runs here
SEND 1 tool_result back, 0 is_error
turn 3 stop_reason: tool_use
ASK issue_refund({'order_id': '1042', 'amount': 400.0}) -> no
SEND 1 tool_result back, 1 is_error
turn 4 stop_reason: pause_turn
SEND the paused response back as it is
turn 5 stop_reason: end_turn
SERVER web_search runs at Anthropic
DONE end_turn: nothing to send
- Turn 1: the lookup is auto, so it runs without a question.
- Turn 2: a refund of 49.90. The person says yes, then it runs.
- Turn 3: a refund of 400. The person says no, and a tool_result is still sent, with
is_error. - Turns 4 and 5: a paused server turn, then a finished web search. Nothing for us to run.
Server tools come back in three shapes
| Shape | stop_reason | What is in the reply | Your job |
|---|---|---|---|
| Server tool only | end_turn | server_tool_use, its result block, the text | Read the text |
| Paused | pause_turn | server_tool_use, no result block yet | Send the reply back as it is, with the same tools |
| Mixed turn | tool_use | server_tool_use plus your own tool_use | Run yours and send only the tool_result blocks; the server tool runs on the next request |
The quick check: a server_tool_use block with no result block means that call is not finished.
Approval in the Agent SDK
If you build on the Claude Agent SDK, the gate is built in. The SDK decides a tool call in this order (Source: Claude Agent SDK docs, Configure permissions):
- Hooks can deny the call or pass it on.
- Deny rules: a match is denied, even in bypass mode.
- Ask rules send the call to the
canUseToolcallback. - The permission mode, the global setting:
default,dontAsk,acceptEdits,plan,bypassPermissionsorauto. - Allow rules: a match is approved and the callback is skipped.
canUseTool: a person decides at runtime.
The warning is in that order. A call approved early, by an allow rule, acceptEdits or bypass, never reaches canUseTool. To check calls that an allow rule approves, put the check in a PreToolUse hook, which runs first.
Break it: skip the declined call
The bug: the person says no, and the harness just skips the call, sending no reply for that tool_use block. The next request fails, because the API finds tool_use ids without tool_result blocks. One decline, and the whole turn fails with no answer for the customer.
The fix is what harness.py already does: answer the decline with is_error: true. Claude reads it and explains to the customer. The gate says no to the action. It never says no to the tool_result.
Quick recap
| Kind | Block | You do |
|---|---|---|
| Client tool | tool_use | Run it, send a tool_result |
| Server tool | server_tool_use | Read the answer; send no tool_result; continue a pause_turn as it is |
| Risky client tool | tool_use behind a gate | Ask first; answer a decline with is_error |
For wider checks on what an agent may do, see guardrails for an LLM agent.
Try it yourself
Change the gate so refunds of 50.00 or less run without asking and larger ones still ask. Where does that rule belong: in tools.py, in approval.py, or in harness.py?
Related course on Udemy
Claude Certified Developer - Foundations (CCDV-F) Exam Prep
Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)Related posts
The Claude Messages API: Your First Call, Field by Field
One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.
Claude Tool Use: How tool_use and tool_result Work in the Messages API
Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.
Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.
Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.