MCP Servers
The Model Context Protocol — Claude's universal connector, with a working server example
What Is MCP?
The Model Context Protocol (MCP) is an open standard created by Anthropic that lets AI models connect to external data sources and tools through a universal interface. A protocol is simply an agreed-upon set of rules for how two systems communicate — like how HTTP defines how your browser talks to websites. MCP defines how AI models talk to tools.
Instead of building custom integrations for every tool, MCP provides a single protocol that any server can implement. Think of it like USB for AI — one standard connector that works with everything.
Why this matters: Without MCP, connecting Claude to your files, databases, or APIs would require custom tool definitions for each one. With MCP, you write a server once using the standard protocol, and any MCP-compatible client (Claude Code, Claude Desktop, Cursor, and more) can use it automatically.
Architecture Overview
The MCP architecture has three layers:
The application that connects to MCP servers. It discovers available tools at startup and lets the AI model call them during conversations. Clients include Claude Code, Claude Desktop, Cursor, and Windsurf.
A program you write that exposes tools, resources, and prompts via the MCP protocol. It runs locally and acts as a bridge between the AI model and your data sources.
The actual data the server connects to — local files, PostgreSQL databases, REST APIs, and more. The MCP server translates AI tool calls into real data operations.
The flow is: Client discovers server tools at startup → AI model decides to call a tool → Client sends the call to the server → Server executes against data sources → Result flows back to the AI model.
Building a Simple MCP Server
Here is a complete, working MCP server in TypeScript. This server exposes a single tool — a note-taking system. You can run this with Claude Code or Claude Desktop:
// npm install @modelcontextprotocol/sdk
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
// In-memory note storage
const notes: Map<string, string> = new Map();
// Create the server
const server = new McpServer({
name: "notes-server",
version: "1.0.0",
});
// Register a tool: add a note
server.tool(
"add_note",
"Save a note with a title and content",
{
title: z.string().describe("Note title"),
content: z.string().describe("Note content"),
},
async ({ title, content }) => {
notes.set(title, content);
return {
content: [{
type: "text",
text: `Saved note: "${title}"`
}]
};
}
);
// Register a tool: list all notes
server.tool(
"list_notes",
"List all saved notes",
{},
async () => {
if (notes.size === 0) {
return { content: [{ type: "text", text: "No notes yet." }] };
}
const list = [...notes.entries()]
.map(([title, content]) => `- **${title}**: ${content}`)
.join("\n");
return { content: [{ type: "text", text: list }] };
}
);
// Start the server (stdio transport)
const transport = new StdioServerTransport();
await server.connect(transport);
This lesson is for Pro members
Unlock all 520+ lessons across 52 courses with Academy Pro.
Already a member? Sign in to access your lessons.