MCP: The Model Context Protocol
In 2024, we are moving beyond simple chat-based AI. The next frontier is agentic AI, and the biggest hurdle is context. How do you give an LLM access to your local files, your database, or your internal APIs in a secure, standardized way?
Enter the Model Context Protocol (MCP). Released by Anthropic in late 2024, it provides an open standard for "clients" (like Claude Desktop) to connect to "servers" (which provide tools and resources).
The Architecture: Client and Server
The MCP architecture consists of:
- MCP Host: The application that wants to use tools (e.g., an IDE, a CLI).
- MCP Server: A small process that exposes resources and tools via the protocol.
- Transport: How they communicate (usually JSON-RPC over Standard Input/Output).
Practical Example: A Simple SQLite MCP Server
Imagine you want your AI assistant to be able to query your local SQLite database. In 2024, you'd write an MCP server like this:
// server.ts
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import sqlite3 from "sqlite3";
const db = new sqlite3.Database("local.db");
const server = new Server({ name: "my-db-server", version: "1.0.0" }, {
capabilities: { tools: {} },
});
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [{
name: "query_db",
description: "Run a read-only SQL query on the local database",
inputSchema: {
type: "object",
properties: { query: { type: "string" } },
required: ["query"],
},
}],
}));
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === "query_db") {
const { query } = request.params.arguments as { query: string };
return new Promise((resolve) => {
db.all(query, [], (err, rows) => {
resolve({ content: [{ type: "text", text: JSON.stringify(rows) }] });
});
});
}
throw new Error("Tool not found");
});
const transport = new StdioServerTransport();
await server.connect(transport);
Why This Matters
Before MCP, every AI tool had its own way of connecting to data. If you wanted to use a tool in VS Code and then in a different AI CLI, the developer had to write integration code twice. Now, you write the MCP server once, and it works anywhere that supports the protocol.
In 2024, MCP is the "USB for AI." It's the standard that will finally allow AI agents to move out of the sandbox and actually do work on our local machines.