Tools & the Model Context Protocol
An agent affects the world only through tools. A tool is any capability the model can invoke — query a database, call an API, run code, search the web. The quality of an agent is bounded as much by the quality of its tool interfaces as by the model behind it. This chapter covers how to design tools the model can use reliably, and how the Model Context Protocol turns bespoke integrations into a standard, reusable ecosystem.
8.1 The tool-calling contract
Mechanically, tool use is disarmingly simple: you describe each tool to the model as a name, a natural-language description, and a typed parameter schema (JSON Schema); the model responds not with prose but with a structured request to call a named tool with arguments; your platform executes it and feeds the result back as an observation (the Act→Observe transition of Ch. 5). Everything hard is in the design. The model can only use a tool as well as it understands it, so the description and schema are the interface — write them for the model as carefully as you would an API for a junior engineer.
Tool names, descriptions, and parameter schemas are read by the model on every call and consume context budget. Make them unambiguous, minimal, and well-typed; return errors the model can act on ("invalid date: expected YYYY-MM-DD") not opaque stack traces. Prefer a few well-designed tools over dozens of overlapping ones.
8.2 Designing tools agents can actually use
- Right granularity — one tool per coherent capability. Too coarse and the model can't compose; too fine and the window fills with schemas and the model gets lost choosing.
- Strict, typed schemas — constrain arguments with enums, formats, and required fields so the model's structured output is validated before execution.
- Actionable errors — return structured, instructive failures the model can recover from, not 500s.
- Idempotency & safety — mark and design mutating tools so retries (Ch. 4) don't double-charge; gate destructive ones behind human approval (Ch. 5).
- Bounded results — paginate or summarize large outputs so a single tool call can't blow the context budget (Ch. 7).
8.3 The Model Context Protocol
Before MCP, every agent framework integrated every tool its own way: an M×N explosion of bespoke connectors. MCP, introduced by Anthropic and now broadly adopted, standardizes the connection between an AI application and external capabilities — the "USB-C port for AI," collapsing M×N into M+N. Build a tool as an MCP server once, and any MCP-compatible host can use it.
stdio for local and streamable HTTP for remote servers.An MCP server exposes three primitives: tools (actions the model may invoke), resources (data the host may read into context, like files or records), and prompts (parameterized templates a user can trigger). The protocol handles capability discovery, so a host can ask a server what it offers at runtime. The strategic consequence is an ecosystem: official and community servers for databases, repositories, browsers, and SaaS products become plug-in capabilities for your agents — and your internal tools, exposed as MCP servers, become reusable across every agent you build.
A tool that reads untrusted data or takes consequential action is exactly the ingredient prompt-injection attacks exploit (the lethal trifecta, Ch. 16). Treat every MCP server as a trust boundary: authenticate it, scope its permissions to the minimum, run third-party servers with isolation, and never assume a server's returned content is safe to act on unchecked. Tool access and identity are governed in Chapters 15–17.