๐Ÿ”ง

MCP (Model Context Protocol)

๐Ÿ‘จโ€๐Ÿณ๐Ÿ‘‘ Master Chef

Model Context Protocol

MCP = Standard protocol to connect LLMs with external tools and data.


Why MCP?

Without MCPWith MCP
Each app its own integrationUnified protocol
Custom APIs per modelWorks with any LLM
Hard to maintainReusable servers

MCP Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚    Client    โ”‚ โ†โ†’  โ”‚    MCP       โ”‚ โ†โ†’  โ”‚   Resource   โ”‚
โ”‚   (Claude)   โ”‚     โ”‚   Server     โ”‚     โ”‚  (DB, API)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ†‘
                     stdio / SSE

Key concepts

ConceptDescription
ToolsFunctions the LLM can call
ResourcesData the LLM can read
PromptsPredefined templates
SamplingLLM 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

ServerFunction
filesystemRead/write files
githubRepos, PRs, issues
postgresSQL queries
brave-searchWeb search

Practice

โ†’ Custom MCP Server