Model Context Protocol servers and clients
The Model Context Protocol (MCP) is an open protocol, introduced by Anthropic in November 2024, that standardises how AI applications connect to tools and data. Before MCP, every agent framework had its own plugin format and every integration was written N times. MCP's pitch, borrowed from the Language Server Protocol, is to write a GitHub or Postgres integration once as a server and use it from any compliant client. As of this writing the latest stable specification revision is dated 2025-11-25.
Why it matters
Tool integration is most of the work in a real agent. MCP turns it into a reusable component with a clear contract:
- Reuse. One server works in Claude, IDEs, desktop apps and your own agents.
- Separation of concerns. The team that owns the CRM ships the CRM server. The agent team just connects to it.
- Discovery at runtime. Clients list a server's tools when they connect, so you can add capabilities without redeploying the agent.
- A shared security vocabulary. The spec spells out consent, authorisation and tool safety expectations, which gives security reviewers something concrete to check.
How it works
MCP uses JSON-RPC 2.0 messages over a stateful connection with capability negotiation at startup. There are three roles:
- Host: the AI application the user interacts with (a chat app, an IDE, your agent service).
- Client: a connector inside the host, one per server connection.
- Server: a process or service that exposes capabilities.
Servers can offer three primitives, each with a different "who controls it" model:
- Tools: functions the model can call (model-controlled). Each has a name, description and JSON Schema
inputSchema. - Resources: data the application can attach as context, such as files or database rows (application-controlled).
- Prompts: reusable templates the user can invoke, often surfaced as slash commands (user-controlled).
Clients can offer features back to servers: sampling (the server asks the host's model to generate something), roots (the filesystem or URI boundaries the server may work in) and elicitation (the server asks the user for more information). There are also utilities for progress, cancellation, logging and error reporting.
Two standard transports exist: stdio, where the host launches the server as a subprocess, and Streamable HTTP, where the server runs independently and can stream with server-sent events. HTTP servers use an OAuth-based authorisation flow. The 2025-11-25 revision added, among other things, experimental support for long-running tasks and URL-mode elicitation.
Rendering diagram…
Reference architecture
A typical enterprise setup has one host connecting to several servers, local and remote, with policy applied in the host:
Rendering diagram…
Code
The TypeScript SDK split into separate server and client packages in its v2 release (the older @modelcontextprotocol/sdk package continues on a v1 branch for fixes). Here is a small server with one tool, and a client that launches it over stdio and calls the tool.
// server.ts
import { McpServer } from "@modelcontextprotocol/server";
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
import * as z from "zod/v4";
const server = new McpServer({ name: "inventory-server", version: "1.0.0" });
server.registerTool(
"check_stock",
{
description: "Return units in stock for a SKU, for example 'SKU-1001'.",
inputSchema: z.object({ sku: z.string() }),
},
async ({ sku }) => ({
content: [{ type: "text", text: `${sku}: 42 units in stock` }],
})
);
await server.connect(new StdioServerTransport());
// client.ts
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
const client = new Client({ name: "agent-host", version: "1.0.0" });
await client.connect(new StdioClientTransport({ command: "npx", args: ["tsx", "server.ts"] }));
const { tools } = await client.listTools();
console.log(tools.map((t) => t.name));
const result = await client.callTool({ name: "check_stock", arguments: { sku: "SKU-1001" } });
for (const block of result.content) {
if (block.type === "text") console.log(block.text);
}
In a real host you would convert the listed tools into your model provider's tool format, and route the model's tool calls back through callTool. Several model APIs and agent SDKs can also connect to remote MCP servers directly, which saves you that glue code.
Trade-offs and pitfalls
- Tool descriptions are untrusted input. The spec says annotations and descriptions should be treated as untrusted unless the server is trusted. A malicious server can hide instructions in a description ("tool poisoning"). Only install servers you trust, and pin versions.
- Consent is the host's job. MCP cannot enforce safety at the protocol level. Your host must get user consent before invoking tools and before exposing user data to servers.
- Too many servers, too many tools. Connecting ten servers can put hundreds of tool schemas in context. Load tools on demand, filter by task, or expose fewer, higher-level tools.
- Token passthrough. Do not forward a user's upstream token blindly to a server. Use the authorisation flow and scope tokens to the server.
- Local servers run with your privileges. A stdio server is just a process on your machine. Sandbox it like any other third-party code.
- Remote servers need production hygiene. Rate limits, timeouts, logging and versioning still apply; MCP does not remove the need for them.
Checklist
- Each server has an owner, a pinned version and a reviewed tool list.
- The host asks for consent before tool calls with side effects.
- Remote servers use the OAuth-based authorisation flow with scoped tokens.
- Tool descriptions from third-party servers are reviewed before enabling.
- The host filters or lazily loads tools to keep context small.
- Local servers run sandboxed with least-privilege filesystem roots.
- All tool calls are logged with server, tool, arguments and result size.