mcp-lab
A hands-on lab for learning the Model Context Protocol (MCP) in TypeScript, providing example tools, resources, and prompts.
README
mcp-lab
A hands-on lab for learning the Model Context Protocol (MCP) in TypeScript.
MCP is an open standard that lets AI apps (like Claude Code or Claude Desktop) connect to external programs in a uniform way — think of it as "USB-C for AI tools": one protocol, many pluggable capabilities.
The mental model
┌─────────────┐ ┌──────────────┐ ┌─────────────────┐
│ HOST │ │ CLIENT │ │ SERVER │
│ (Claude │◄──────►│ (one per │◄──────►│ (this repo: │
│ Code, etc.)│ │ server, in │ │ mcp-lab) │
│ │ │ the host) │ │ │
└─────────────┘ └──────────────┘ └─────────────────┘
the AI app speaks the exposes tools,
protocol resources, prompts
- Host — the AI application the user interacts with.
- Client — the connector the host spins up for each server.
- Server — a program (this repo) that exposes capabilities.
- Transport — how client and server talk. This lab uses stdio (the host launches the server and pipes JSON-RPC over stdin/stdout). The other common transport is HTTP.
The three things a server can expose
| Capability | Who triggers it | Analogy | Example here |
|---|---|---|---|
| Tool | the model | a POST / an action | add, greet |
| Resource | the app/model | a GET / a file | lab://about |
| Prompt | the user | a slash command | explain-like-im-five |
Setup
npm install
Requires Node 18+ (you have v22 ✅).
Run it
Option A — the MCP Inspector (best for learning). A web UI that connects to your server so you can click every tool, resource, and prompt by hand:
npm run inspect
Then open the URL it prints. Try the add tool — pass a: 2, b: 3.
Option B — connect it to Claude Code. Register the server so Claude can use its tools directly. From this folder:
claude mcp add mcp-lab -- npx tsx src/server.ts
Then ask Claude: "Use the add tool to add 21 and 21."
Option C — connect it to Claude Desktop. Add this to your
claude_desktop_config.json (Settings → Developer → Edit Config), using an
absolute path, then restart Claude Desktop:
{
"mcpServers": {
"mcp-lab": {
"command": "npx",
"args": ["tsx", "C:\\CLAUDE\\Project\\mcp-lab\\src\\server.ts"]
}
}
}
What's in here
-
src/server.ts— the core server, heavily commented. Read it top to bottom. Exposesadd,multiply,greet, thelab://aboutresource, and theexplain-like-im-fiveprompt. -
src/weather-server.ts— a second server that calls a real web API (free, no key). Showsfetch()inside a tool and clean error handling withisError: true. Inspect it with:npx @modelcontextprotocol/inspector tsx src/weather-server.ts
The golden rule of stdio servers
Never use console.log() in a stdio MCP server — stdout is the protocol
channel and logging there corrupts messages. Use console.error() (stderr) for
debugging instead.
Exercises (learn by extending)
- Add a
multiplytool. Copy theaddblock, change the math. - Add a tool that calls a real API (e.g. fetch the weather) — this is where
MCP gets powerful. Use
fetch()inside the handler. - Make a dynamic resource whose content depends on the URI (look up
ResourceTemplatein the SDK). - Return an error from a tool by setting
isError: truein the result and see how the host reacts.
Where to go next
- Spec & docs: https://modelcontextprotocol.io
- TypeScript SDK: https://github.com/modelcontextprotocol/typescript-sdk
- Inspector: https://github.com/modelcontextprotocol/inspector
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.