Skip to content

MCP (Model Context Protocol) ​

Stop writing the same tool adapter for every application, and know when a server is worth building.

In this chapter: the N×M problem it solves · clients, servers and transports · what a server exposes · connecting one · when to build one · the trust boundary

💡 The Core Idea ​

Before MCP, every application that wanted the model to reach your issue tracker wrote its own adapter. Five applications and eight systems meant forty adapters, all doing the same thing differently. MCP turns that N×M problem into N+M. Each system exposes one server. Each application speaks one client protocol.

It is the same move as the Language Server Protocol, and worth naming that way in an interview. LSP did not make editors better at language analysis. It stopped every editor rebuilding it for every language. MCP does not make models better at using tools. It standardises how a tool describes itself.

MCP is plumbing, not intelligence. It changes who writes the adapter, not what the model can do.

How It Works ​

Three roles ​

RoleIsExample
HostThe application the user interacts withAn IDE, a chat product, your assistant
ClientThe connection the host holds to one serverOne per server, managed by the host
ServerA process exposing capabilities over the protocolA docs server, a database server

A host runs many clients, one per server. The model itself is not in this picture at all. The host collects tool definitions from its clients and passes them into the model call as ordinary tool definitions. Everything from Tool Calling and the Tool Surface still applies underneath.

What a server exposes ​

PrimitiveWhat it isControlled by
ToolsFunctions the model can callThe model, via the host
ResourcesReadable content, addressed by URIThe application
PromptsReusable templated instructionsThe user, usually as a command

The split matters, and people often miss it. Tools are model-driven and can have effects. Resources are application-driven and read-only: a file, a table, a document. Attaching a resource is not the same as letting the model call a tool. Blur the two, and a read-only integration gains write access nobody reviewed.

Transports ​

text
stdio  →  local process, same machine, no network
http   →  remote server, streamable HTTP, needs auth

Two transports, and the choice is really a security question, not a networking one.

stdio launches the server as a child process and talks over standard input and output. It is the right choice for local tooling, such as a file server or a local database. It inherits the permissions of whoever started it.

Streamable HTTP is for remote servers and brings everything remote implies: authentication, transport security, rate limits and an audit trail. An HTTP MCP server is a public API with a tool-shaped description, and it needs the controls of one.

Connecting to a server ​

typescript
import { createMCPClient } from '@ai-sdk/mcp';
import { generateText, isStepCount } from 'ai';

const client = await createMCPClient({
  transport: { type: 'http', url: 'https://internal.example.com/mcp', headers: { Authorization: bearer } },
});

try {
  const mcpTools = await client.tools();   // discovered at runtime, not compiled in
  const { text } = await generateText({
    model: 'anthropic/claude-sonnet-4.6',
    tools: { ...mcpTools, ...localTools },
    stopWhen: isStepCount(6),
    messages,
  });
} finally {
  await client.close();
}

Two things in that snippet deserve attention. Tools are discovered at runtime, so a server can change what it offers between deployments of your application. That helps iteration, and it is a reason to pin versions for anything you depend on. Also, merging tool sets by spread means a later server silently overrides an earlier server's tool of the same name. Namespace them (prefix each name with its server).

⚠️ Moving target: this chapter is stamped against MCP revision 2025-11-25. Both the specification and the client packages change within months. The SSE transport is already legacy, in favour of streamable HTTP. The lasting principle is the three primitives and the client/server split. Check the current revision before implementing.

When building one is worth it ​

SituationBuild a server?Why
One application, tools you control❌ NoDefine them in code; the protocol is pure overhead
Several applications, one internal system✅ YesThis is exactly N×M
Third parties should reach your product✅ YesA tool-shaped public integration surface
An existing server does it❌ Use itAuditing someone's server is cheaper than writing yours
A short-lived prototype❌ NoA process boundary you do not need yet

The honest default is no. A single application with five in-repo tools gets nothing from a protocol except a process to supervise and a schema to keep in sync.

The trust boundary ​

An MCP server is code you did not write. It describes tools in text the model will read, and it runs with whatever credentials you gave it. Each of those facts is a risk.

  • Tool descriptions are prompt text. A malicious server can write a description that tells the model to exfiltrate (smuggle out) context inside an argument. Review descriptions, not just code.
  • Servers can change what they expose. Tools discovered at runtime can differ from the ones you reviewed. Pin versions for anything you depend on.
  • A local server has the user's permissions. A stdio server started from a developer machine can read whatever that developer can read, including credentials on disk.
  • Combining servers combines their reach. A server that reads private data plus a server that can post publicly is an exfiltration path neither one has alone.

When to Use It ​

ScenarioReach for
Your application, your tools, one codebasePlain tool definitions
Same integration wanted by three internal appsAn MCP server
Connecting an assistant to an existing ecosystemAn MCP client
Exposing your product to AI applications generallyAn MCP server, treated as a public API

Common Mistakes ​

❌ Building a server for one consumer

The protocol solves N×M. With N=1 you have added a process, a schema and a version to maintain.

❌ Trusting a third-party server because the code looks fine

The tool descriptions reach the model as instructions. That is the injection surface, and it is not in the code review most teams run.

❌ Merging tool sets from several servers without namespacing

Identical names collide silently and the last one wins. The model then calls a tool you did not expect.

✅ Give a remote MCP server the controls you would give any public API

Authentication, per-caller rate limits, least-privilege credentials, and an audit log of every tool invocation. It is an API. The tool-shaped description does not change that.

🔑 Key Takeaways ​

  • MCP standardises how tools describe themselves, turning N×M integrations into N+M.
  • A host runs one client per server. The model sees ordinary tool definitions and knows nothing of the protocol.
  • Tools are model-driven and can act. Resources are application-driven and read-only. Do not mix them up.
  • Tool descriptions from a third-party server are untrusted prompt text reaching your model.
  • Build a server when several applications need the same integration; otherwise define tools in code.

Interview Questions ​

Q: What problem does MCP actually solve?

Adapter duplication. Every application that wanted a model to reach a given system used to write its own integration. Five applications and eight systems meant forty adapters. MCP defines one protocol, so each system ships one server and each application ships one client. It is the Language Server Protocol argument applied to tools. It does not make the model smarter. It stops everyone rewriting the same glue.

Q: Would you build an MCP server for your team's internal API?

Only if more than one application needs it. With a single consumer, in-repo tool definitions are simpler, faster and easier to type-check. The protocol only adds a process boundary and a schema to keep in sync. Once a second and third application want the same integration, the arithmetic flips. Think of a chat product, an IDE and a support tool. One server then beats three adapters.

Q: What is the security risk in connecting to a third-party MCP server?

Its tool descriptions are prompt text that goes straight into the model's context. A server can describe a harmless-looking tool with hidden instructions. Those steer the model into passing along data from elsewhere in the conversation. Reviewing the server's source code does not catch it, because the payload is in the description. Combining servers is the sharper version. One that reads private data and one that can post externally form an exfiltration path that neither has alone.

Q: How do tools and resources differ, and why does it matter?

The model invokes tools, and tools can have side effects. Resources are content the application chooses to attach, addressed by URI and read-only. The difference decides who is in control. Attaching a resource is the application deciding what the model sees. Exposing a tool gives the model the power to act. Treat them the same, and a read-only integration gains write access nobody signed off on.

Q: A tool call through an MCP server fails. Where do you look?

The same places as any tool call, plus one. Transport first: is the process alive, and is the HTTP endpoint authenticating? Then the schema, because arguments still have to validate. Then the description, since the model may call the wrong tool for an understandable reason. The extra place is version drift. Tools are discovered at runtime, so the server may expose something different from what you reviewed.

The whole book, free to read. Generated from the manuscript on every change.

Your progress

Tick each chapter in the sidebar once you have read and understood it. Your name and email keep the ticks on any device.

Your name and email are stored to save your progress. Nothing else is done with them.