Server tools: web search and code execution

Claude API · Practical · 11 min

Server tools add live information and computation without you writing or hosting any tool code.

The tools in the last lesson were client tools: Claude asks, your code runs them. Server tools run on Anthropic's side. You list them in tools, and Claude uses them inside the same request; the results come back already filled in.

The main ones:

  • Web search: Claude searches the web and answers with citations (links to the sources it used).
  • Web fetch: reads the full content of a given web page or PDF.
  • Code execution: runs Python and shell commands in a sandbox, a sealed-off computer, which is handy for maths and data analysis.

A server tool entry has a versioned type such as web_search_20260318 and a name. The date in the type is the tool version; newer versions add features, so check the docs for the current string. Options like max_uses, allowed_domains and blocked_domains limit what the tool may do.

In the response you will see new block types: server_tool_use (what Claude searched for) and web_search_tool_result (the results), followed by text blocks whose citations point to sources. Show those citations to your users. In a multi-turn chat, send these blocks back unchanged.

Server tools cost extra on top of tokens (web search is billed per search), and an organisation admin can disable them. Search results are outside content, so treat them as untrusted: a web page may contain text that tries to give Claude instructions.

Example

import anthropic

client = anthropic.Anthropic()
resp = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=2048,
    tools=[{
        "type": "web_search_20260318",   # versioned; check the docs
        "name": "web_search",
        "max_uses": 3,
    }],
    messages=[{"role": "user", "content": "What changed in the latest Python release?"}],
)

for block in resp.content:
    if block.type == "server_tool_use":
        print("searched:", block.input["query"])
    elif block.type == "text":
        print(block.text)
        for c in block.citations or []:
            print("  source:", c.url)

Remember

  • Server tools run at Anthropic; no handler code needed
  • Tool types are versioned strings like web_search_20260318
  • Show citations; treat fetched content as untrusted

Watch out for

  • Leaving web search unlimited; set max_uses and domain filters to control cost and sources.

Check yourself

  1. What is the key difference between a server tool and a client tool?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool