The Model Context Protocol (MCP)
As agents move into production, the "Tool Integration" problem explodes. Writing custom glue code for every database (Postgres, Slack, GitHub, Drive) is unscalable and insecure.
Enter MCP (Model Context Protocol). It is an open standard that standardizes how AI assistants connect to systems. Think of it as "USB-C for AI applications."
What is MCP?
MCP defines a standard communication protocol (JSON-RPC) between:
- Hosts (Clients): The AI application (e.g., Claude Desktop, Cursor, Your Custom Agent).
- Servers: A lightweight service that exposes Resources, Prompts, and Tools.
Instead of your agent needing a custom "Postgres Adapter", it simply connects to a standard "Postgres MCP Server".
Core Primitives
1. Resources
Data that can be read by the LLM. Like files or database rows.
- URI-based addressing (
postgres://users/123). - Passive: The agent reads them to get context.
2. Tools
Exectuable functions (as discussed in Chapter 4).
- Active: The agent calls them to perform actions (
execute_sql,git_commit).
3. Prompts
Reusable prompt templates stored on the server side.
- Allows the server to define "best practice" ways to interact with its data.
Building an MCP Server
You can build an MCP server in TypeScript or Python. It runs locally or remotely.
// Simple MCP Server (TypeScript)
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
const server = new McpServer({ name: "weather-server", version: "1.0.0" });
// Define a Tool
server.tool(
"get-weather",
{ city: z.string() },
async ({ city }) => {
return { content: [{ type: "text", text: `Weather in ${city}: Sunny` }] };
}
);
// Start the server (stdio transport)
const transport = new StdioServerTransport();
await server.connect(transport);Any MCP-compliant client (like Claude Desktop) can now "plug in" this server and instantly gain the ability to check the weather, without you modifying the client code.
Why This Matters for Engineering
- Decoupling: Your agent logic is separate from your data connectors.
- Security: The MCP server runs in its own process. You can sandbox it. The agent only sees what the MCP server explicitly exposes.
- Reusability: Write a "Internal Company API" MCP server once, and every AI agent in your company (Cursor, Chatbots, CI/CD bots) can reuse it.
Summary
MCP is the future of agent connectivity. It moves us away from brittle, proprietary integrations toward a standardized ecosystem where agents can "hotswap" capabilities simply by connecting to a new server.