MCP (Model Context Protocol) is a common standard for connecting AI apps with external tools and data. Once you set up a tool as an MCP server, it works the same way from any app that supports MCP. In the previous chapter, we ran a minimal agent that connected tools to an LLM and ran its own loop. In this chapter, you'll learn how to stop building each tool from scratch and connect tools in a standard way with MCP, along with how to design the tools you hand over so they're used safely.
The goal: connect tools safely through a standard, without building each one yourself
Why Tool Connections Are the Core of Agents
An LLM, however capable, can only generate words. It can't check today's inventory or write a line to a file without a way to reach the outside world. An agent can run the loop of "investigate, act, verify" because it has tools that let it act on the outside world.
In other words, what an agent can do depends on which tools it's connected to, and what permissions it has on them. Two agents running on the same LLM can differ enormously: one that only has a calculator, and one connected to a database, search, files, and an internal API. Depending on the goal, connecting the right tools can expand the work you can hand off far more than swapping in a higher-end model.
💡 "Well-equipped" beats "clever." Even a brilliant person can't get anything done with an empty toolbox. Much of agent development goes into designing which tools to give, and how to hand them over safely. This chapter is at the core of that.
The Limits of Plain Tool Definitions
In the previous chapter, you defined tools yourself. You wrote a function, passed its name, arguments, and description to the LLM, and when a call came in, you ran it and returned the result. This flow is correct and still the foundation. For a small process used in only one app, this approach is enough. The problem comes when you have to rebuild the same tool for each tool and each project.
Take a "database search tool" as an example. You write the connection logic, build the queries, format the results, handle errors, and handle credentials securely. Your project, the team next door, and someone using a different language each implement this whole set on their own. Developers around the world keep rebuilding the same tool. That is the reality of plain tool definitions.
A tool written for one project is tied to that framework and language, which makes it hard to take elsewhere.
Connecting M kinds of tools to N agent platforms theoretically requires N×M sets of connection code.
Each time the specification of a connected service changes, you have to fix each scattered custom tool one by one.
This is much like the era when each peripheral needed its own cable. Printers had printer-specific ports and mice had mouse-specific ports, and the more devices there were, the more connection types exploded. A "common port" removes most of this hassle at once. That is where MCP comes in.
What Is MCP? A Common Standard for Tool Connections
MCP (Model Context Protocol) is an open standard for connecting AI with external tools and data in a standard way. Anthropic released it as open source in November 2024, and since then other companies' products, including ChatGPT, Cursor, Gemini, Microsoft Copilot, and Visual Studio Code, have added support. In December 2025, it was donated to the Agentic AI Foundation (AAIF) under the Linux Foundation, so the specification is now developed without belonging to any single company.
To put MCP's idea in one phrase: it is "USB for AI tool connections." Just as USB let peripherals from any manufacturer work through the same port, an MCP-compatible tool works with any MCP-compatible app by simply plugging in. When builders and users follow the same agreement, the N×M combinations collapse into N+M.
Runs inside the agent you build or an app such as Claude. It is the side that asks the server "What tools can I use?" and calls the tools it needs.
Publishes features such as file operations, database search, and SaaS integration as "tools". One server can offer several tools.
The two sides exchange messages in a set order. First, the client receives from the server a list of available tools, along with each tool's name, description, and argument format. The LLM looks at this list and chooses a suitable tool, the client calls it, and the server runs it and returns the result. In the official tool specification, retrieving the list is called tools/list, and calling a tool is called tools/call. The core of MCP is that this round trip works without individual implementations for each tool.
Client → Server: "Tell me which tools are available" (tools/list) Server → Client: "search_docs / read_file / query_db are available; here are the descriptions" LLM decides : "I'll call query_db with the arguments {sql:"..."}" Client → Server: "Run query_db" (tools/call) Server → Client: "The result is these rows of data"
The contents of the list are not fixed. Under the specification, a server can narrow the tools it returns based on the user's permissions, and the list can change later. Remember that "the connection works" and "the tools you need can be used" are two different things.
The official specification defines two standard transports (communication methods). Both exchange the same messages, and the way the client handles them barely changes.
The client launches the server as a child process and communicates through standard input and output. It suits connecting to your own files or a development database. Pass credentials from the execution environment, such as through environment variables.
Sends requests over HTTP to the server's URL. It suits things like SaaS integrations shared across a team. When authentication is required, use the OAuth-based authorization defined in the specification.
📖 Watch the specification version. MCP specification versions are dated. As of October 2026, the current version is 2026-07-28. From this version on, versions are negotiated per request, which differs from the procedure used in versions before 2025-11-25, where the client and server agreed on the version at connection time through initialize. Don't follow older procedures as they are. Check which version your SDK, app, and server support. If you'd like to read the background and terms explained in plain language first, the "What Is MCP?" explainer will make this chapter easier to follow.
Using and Building MCP Servers
The best part of MCP is that you can use servers that are already published as they are. For common tools, the service provider often offers an official MCP server, and you can find them in the official MCP Registry. Connect them to your own agent, and its capabilities grow immediately, with no need to rebuild anything.
Reads and writes in a specified folder. This is the base for having an agent read documents or write out deliverables.
Runs SQL and reads schemas. When asked to "summarize," it can query real data and answer.
Web search and internal knowledge-base search. This is the "research hand" that pulls up current information and sources.
Issue tracking, chat, storage, and more. Your existing business tools can become the agent's hands.
The connection steps themselves are simple. Register the server's launch command (stdio) or URL (HTTP) in your client settings, and complete authentication if needed. After that, the agent receives the tool list and calls tools as needed. You don't have to write the internals of a "database search tool" yourself. Your job becomes combining the tools provided to suit your goal.
Before connecting, however, check the provider, maintenance status, required permissions, and the code that gets launched. For example, the Filesystem, Git, and Fetch servers in the official servers repository are reference implementations for teaching how the specification and SDK work. The repository itself states that they are not production-ready finished products. Being listed in the Registry is not a guarantee of safety either.
⚠️ Don't connect everything just because it's convenient. Each server you add increases the number of tool descriptions you pass to the LLM, which scatters its decisions and widens the room for mistakes. The basic rule is to connect only the tools that the agent's purpose truly requires.
You Can Also Build Your Own Server
For tools without a ready-made server, such as an internal custom API or specialized business logic, you can write your own MCP server. This is MCP's strength: once you publish it as a server, any compatible agent can use it the same way. A tool built for one project can be reused in the next project, or by another agent on your team, without rewriting it.
Building a server comes down to: define the functions you want to offer as tools, declare their names, arguments, and descriptions, and when they are called, run the processing and return the result. The idea is the same as the plain tool definitions from the previous chapter, but the decisive difference is that the output goes to a common MCP port rather than to a "specific agent." Note that only the connection agreement is standardized. Input validation, permission checks, and keeping up with changes in the connected service's specification remain the responsibility of whoever builds the server, as before.
🛠 If you want to go into implementation. For concrete code that builds agents and tool connections with Claude, the Claude Agent SDK guide is practical. The SDK includes a way to handle MCP servers, and you can connect existing servers or build your own by following the official documentation.
The Order for Troubleshooting When Something Doesn't Work
- The connection doesn't get through: For stdio, check the launch command and execution environment. For HTTP, check the URL and communication conditions. Also read any error messages about version support or authentication.
- The tool you need doesn't appear in the list: Check whether the server provides that tool, whether it appears under your user's permissions, and whether the app is restricting it.
- The call goes through but fails: Check the arguments, the target data, the execution permissions, and the error returned. Don't widen permissions or repeat the same operation until something works.
What Tools to Give, and How
Once you can "connect" tools, the next question is "what to give, and how." This is a key design point that determines an agent's quality and safety, and it also forms the foundation for the chapters that follow. Keep three principles in mind.
Give only the tools and scope that the task requires. If reading is enough, don't grant write permission. The basics are a restricted read-only account for a database, and only the target folder for files.
The LLM decides whether to use a tool based on its name, description, and argument definitions. Write specifically what it does, when to use it, what the arguments mean, and when not to use it. Vague descriptions lead to misuse.
Don't place irreversible operations such as writing, deleting, billing, or running commands on the same level as read-only tools. Always add a confirmation step before execution, limits on targets, and logging.
There is a trap with ②. Writing "does not update" in a description does not reduce the actual permissions. A description is guidance for the LLM, while restrictions must be enforced in the implementation. The official specification requires servers to validate input and control access, and recommends that apps obtain user confirmation before important operations. Annotations attached to tools, such as "read-only," should also not be taken at face value unless they come from a trusted server.
③ is especially important. Tools for "looking things up" (search, reference, reading) tend to cause little damage even when called by mistake. Still, they can expose confidential information, or the content they read may contain hidden instructions such as "send this data to another destination." Tools for "changing things" (writing, deleting, sending, executing) can produce irreversible results from a single mistake. Distinguish read-only tools from write tools, and layer guards on the latter is the golden rule.
| Type | Examples | Risk | Guideline for granting |
|---|---|---|---|
| Read-only | Search, lookup, file reading | Low (watch for data leaks and for instructions hidden in results) | Relatively open. Keep the scope narrow |
| Write | File updates, database writes, sending | High (hard to undo) | Require confirmation, limits, and logging |
| Execute | Running commands, external calls, billing | Highest (an entry point for runaway behavior and abuse) | Guard by default and insert human approval |
Example: A Tool That Only Reads Ticket Status
Suppose the request is "Check the status of ticket DEMO-42 and draft a reply. Don't send it." The following single tool is enough.
{
"name": "get_ticket_status",
"description": "Looks up the status of an allowed ticket ID. Does not send replies or change status.",
"inputSchema": {
"type": "object",
"properties": {
"ticket_id": { "type": "string" }
},
"required": ["ticket_id"],
"additionalProperties": false
}
}
This tool only returns the status of one ticket. It cannot send a reply or change the status. On the server side, each time it is called, the server checks whether the calling user is allowed to view that ID. (Knowing an ID does not prove you're allowed to view it.) If sending becomes necessary, prepare it as a separate tool where a person checks the recipient and the message body first.
Be careful when specifying folder scope as well. MCP has a mechanism called roots for telling a server which folders are relevant, but it does not restrict access, and it is deprecated in the current version. Apply scope restrictions through the server's settings, or through OS and connected-service permissions.
🔒 We'll cover this thoroughly in Chapter 6. Controlling dangerous tools, defending against prompt injection, and designing approval flows are unavoidable topics when you put an agent into production. They are covered in Chapter 6, "Guardrails and Safety". For this chapter, take away the sense that tools carry different levels of danger. Not connecting untrusted MCP servers without thought is also a valuable habit.
Advanced Tools Such as Browser Control
Among tools, one that has drawn particular attention recently is browser control. The agent looks at the screen, follows links, fills in forms, and presses buttons. If an agent can take over the operations a person performs in a browser, many web services without a dedicated API also become things it can act on. Implementations that offer browser control as an MCP server have appeared, and the barrier to connecting has come down.
However, this is also one of the most powerful and most risky tools. Instructions on the screen can be taken at face value (manipulation and misinformation), clicks or submissions can happen unintentionally, and information can be exposed from pages where you're logged in. The cautions for "execute" tools in the previous section apply in full. Using MCP does not eliminate these risks. It's wise to start with read-oriented uses such as browsing and gathering information, separate out operations that involve input, submission, or purchases, and set up guards carefully.
🌐 How much can you hand over? We test the realistic capabilities and limits of browser-operating agents in How Far Can AI Automate Browser Tasks?. Knowing the sense of distance, that it is not all-powerful but is practical when the use is narrowed, will keep your tool choices steady.
Beyond browsers, the more advanced a tool is, the more its potential and its possible consequences grow in proportion. The more powerful the tool you hand over, the more carefully you should apply the three principles of permissions, descriptions, and guards. This is the message we have repeated throughout this chapter.
- What an agent can do depends on which tools it is connected to, and with what permissions.
- Building plain tools yourself makes them hard to reuse and prone to the N×M combination problem.
- MCP is an open standard for connecting AI with external tools in a standard way. Its clients (the side that uses tools) and servers (the side that provides them) exchange tool lists and calls under the same agreement, making it an "AI version of USB."
- The transports are stdio (started locally) and Streamable HTTP (connects to a URL). Connect ready-made servers after checking the provider and permissions, and turn your own tools into custom servers so they can be reused.
- The principles for handing over tools are ① minimal permissions ② specific descriptions ③ treat dangerous tools separately. Restrictions must be enforced in the implementation, not in descriptions, and be especially careful with powerful tools such as browser control.
Now that you know how to assemble tools, the next step is "adding more agents." Designs that split work across several agents, instead of one agent handling more than it can manage, come next. In Chapter 4, "Multi-Agent Design," you'll learn about dividing roles and coordination between agents (A2A).