Model Context Protocol
MCP = Standard protocol to connect LLMs with external tools and data.
Why MCP?
| Without MCP | With MCP |
|---|---|
| Each app its own integration | Unified protocol |
| Custom APIs per model | Works with any LLM |
| Hard to maintain | Reusable servers |
MCP Architecture
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ Client โ โโ โ MCP โ โโ โ Resource โ
โ (Claude) โ โ Server โ โ (DB, API) โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ
stdio / SSE
Key concepts
| Concept | Description |
|---|---|
| Tools | Functions the LLM can call |
| Resources | Data the LLM can read |
| Prompts | Predefined templates |
| Sampling | LLM generates content |
Basic MCP server
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server({
name: "my-server",
version: "1.0.0"
});
// Define tool
server.setRequestHandler("tools/list", async () => ({
tools: [{
name: "greet",
description: "Greet a person",
inputSchema: {
type: "object",
properties: {
name: { type: "string" }
}
}
}]
}));
// Implement tool
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "greet") {
return { content: [{ type: "text", text: `Hello ${request.params.arguments.name}!` }] };
}
});
// Start
const transport = new StdioServerTransport();
await server.connect(transport);
Configure in Claude Desktop
{
"mcpServers": {
"my-server": {
"command": "node",
"args": ["./build/index.js"]
}
}
}
Popular MCP servers
| Server | Function |
|---|---|
| filesystem | Read/write files |
| github | Repos, PRs, issues |
| postgres | SQL queries |
| brave-search | Web search |