Lesson 204 of 2116
Building a Minimal MCP Server
Model Context Protocol lets agents plug into your tools. A 40-line server exposes a real capability to Claude.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1One Protocol, Many Tools
- 2MCP
- 3tools
- 4stdio transport
Concept cluster
Terms to connect while reading
Section 1
One Protocol, Many Tools
An MCP server exposes tools over stdio or HTTP. Any MCP-capable client (Claude Desktop, Cursor, Claude Code) can call them. Build once, use everywhere.
Official SDK plus Zod for schemas.
npm install @modelcontextprotocol/sdk zodTwo tools, typed inputs, string outputs. Run with `node server.js` from an MCP-capable client config.
// server.ts
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({
name: "word-tools",
version: "0.1.0",
});
server.tool(
"word_count",
"Count words in a string.",
{ text: z.string().min(1) },
async ({ text }) => {
const count = text.trim().split(/\s+/).length;
return {
content: [{ type: "text", text: String(count) }],
};
}
);
server.tool(
"reverse",
"Reverse a string.",
{ text: z.string() },
async ({ text }) => ({
content: [{ type: "text", text: [...text].reverse().join("") }],
})
);
const transport = new StdioServerTransport();
await server.connect(transport);Point Claude Desktop at your script. Restart, and the tools appear.
// claude_desktop_config.json snippet
{
"mcpServers": {
"word-tools": {
"command": "node",
"args": ["/absolute/path/to/server.js"]
}
}
}Understanding "Building a Minimal MCP Server" in practice: AI-assisted coding shifts work from syntax recall to design thinking — models handle boilerplate so you focus on architecture. Model Context Protocol lets agents plug into your tools. A 40-line server exposes a real capability to Claude — and knowing how to apply this gives you a concrete advantage.
- Apply MCP in your ai-coding workflow to get better results
- Apply tools in your ai-coding workflow to get better results
- Apply stdio transport in your ai-coding workflow to get better results
- Apply schema in your ai-coding workflow to get better results
- 1Use AI to generate unit tests for an existing function
- 2Ask AI to refactor a messy function and explain the changes
- 3Have AI suggest a code review for a recent pull request
Key terms in this lesson
The big idea: MCP is the USB port for agents. Write a tiny server once, and every MCP client can use your tools.
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “Building a Minimal MCP Server”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Creators · 45 min
Installing and Using the OpenAI Codex CLI
Codex CLI is OpenAI's terminal coding agent. It runs locally, supports MCP, and ships a codex cloud mode for background tasks. Let's install it and compare it honestly to Claude Code.
Creators · 40 min
Agents vs. Autocomplete — the Mental Model Shift
Autocomplete is a suggestion. An agent is an actor. The mental model you bring to each is different, and conflating them is the number-one reason teams trip over AI coding.
Creators · 50 min
Test-Driven AI Development
TDD was already the gold standard. Paired with an agent, it becomes the tightest feedback loop in software. Here's the full workflow and the pitfalls.
