Development Intermediate

MCP (Model Context Protocol)

Open protocol created by Anthropic that standardizes how AI agents connect to external applications and services.

Pronunciation

/ɛm siː piː/
"em-see-pee"
Listen on: Forvo

What is it

MCP (Model Context Protocol) is an open protocol developed by Anthropic that defines how AI models (like Claude, ChatGPT, Gemini) connect to external applications and services.

Think of MCP as a “USB for AI”: a standard that allows any AI to connect to any service consistently.

Pronunciation

IPA: /ɛm siː piː/

Sounds like: “em-see-pee” - each letter pronounced separately

Common mistakes:

  • ❌ “m-c-p” (rushing through without clear separation)

Why MCP exists

The problem before MCP

┌─────────────────────────────────────────────────────────┐
│                   NO STANDARD (Before)                   │
├─────────────────────────────────────────────────────────┤
│                                                          │
│   Claude ────→ Anthropic Plugin ────→ Your App          │
│                                                          │
│   ChatGPT ───→ OpenAI Plugin ───────→ Your App          │
│                (different format)                        │
│                                                          │
│   Gemini ────→ Google Extension ────→ Your App          │
│                (yet another format)                      │
│                                                          │
│   = 3 different integrations for the same thing         │
│                                                          │
└─────────────────────────────────────────────────────────┘

The solution with MCP

┌─────────────────────────────────────────────────────────┐
│                   WITH MCP (Now)                         │
├─────────────────────────────────────────────────────────┤
│                                                          │
│   Claude  ─┐                                             │
│            │                                             │
│   ChatGPT ─┼────→ MCP Server ────→ Your App             │
│            │      (one format)                           │
│   Gemini  ─┘                                             │
│                                                          │
│   = 1 integration works for all AIs                     │
│                                                          │
└─────────────────────────────────────────────────────────┘

MCP Architecture

MCP defines three main components:

ComponentRoleExample
HostThe AI applicationClaude Desktop, Cursor
ClientMaintains connection with serversMCP Library
ServerExposes resources and toolsYour backend

Communication flow

┌──────────┐      ┌──────────┐      ┌──────────┐
│   Host   │      │  Client  │      │  Server  │
│ (Claude) │ ←──→ │  (MCP)   │ ←──→ │(Your API)│
└──────────┘      └──────────┘      └──────────┘
     │                 │                  │
     │   "List my      │                  │
     │    tasks"       │                  │
     │ ───────────────→│                  │
     │                 │  tools/list      │
     │                 │ ────────────────→│
     │                 │                  │
     │                 │  [getTasks,      │
     │                 │   createTask]    │
     │                 │ ←────────────────│
     │                 │                  │
     │                 │  tools/call      │
     │                 │  getTasks()      │
     │                 │ ────────────────→│
     │                 │                  │
     │                 │  [{id:1, ...}]   │
     │                 │ ←────────────────│
     │   "You have 5   │                  │
     │    tasks..."    │                  │
     │ ←───────────────│                  │

Practical example: Basic MCP Server

// server.ts - A minimal MCP server
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = new Server({
  name: "my-tasks-server",
  version: "1.0.0",
});

// Define available tools
server.setRequestHandler("tools/list", async () => ({
  tools: [
    {
      name: "get_tasks",
      description: "Gets the list of pending tasks",
      inputSchema: {
        type: "object",
        properties: {
          status: {
            type: "string",
            enum: ["pending", "completed", "all"]
          }
        }
      }
    }
  ]
}));

// Implement the tool
server.setRequestHandler("tools/call", async (request) => {
  if (request.params.name === "get_tasks") {
    const tasks = await fetchTasksFromDB(request.params.arguments.status);
    return { content: [{ type: "text", text: JSON.stringify(tasks) }] };
  }
});

// Start server
const transport = new StdioServerTransport();
await server.connect(transport);

MCP Capabilities

MCP allows exposing three types of capabilities:

1. Tools

Functions that AI can execute:

{
  "name": "send_email",
  "description": "Sends an email to a recipient",
  "inputSchema": {
    "type": "object",
    "properties": {
      "to": { "type": "string" },
      "subject": { "type": "string" },
      "body": { "type": "string" }
    },
    "required": ["to", "subject", "body"]
  }
}

2. Resources

Data that AI can read:

{
  "uri": "file:///config/settings.json",
  "name": "System configuration",
  "mimeType": "application/json"
}

3. Prompts (Templates)

Reusable instructions:

{
  "name": "code_review",
  "description": "Template for code review",
  "arguments": [
    { "name": "file", "required": true }
  ]
}
ServerFunctionMaintainer
filesystemLocal file accessAnthropic
githubRepo operationsAnthropic
postgresPostgreSQL queriesAnthropic
slackMessages and channelsCommunity
google-driveDrive filesCommunity

Configuration in Claude Desktop

// ~/Library/Application Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "my-server": {
      "command": "node",
      "args": ["/path/to/server.js"],
      "env": {
        "API_KEY": "your-api-key"
      }
    }
  }
}

Security in MCP

Security principles

  1. Least privilege: Expose only what’s necessary
  2. Validation: Verify all inputs
  3. Authentication: Use tokens for access
  4. Auditing: Log all operations

Validation example

server.setRequestHandler("tools/call", async (request) => {
  // Validate that the tool exists
  if (!allowedTools.includes(request.params.name)) {
    throw new Error("Tool not allowed");
  }

  // Validate parameters
  const validated = schema.parse(request.params.arguments);

  // Execute with limited permissions
  return executeWithSandbox(request.params.name, validated);
});
  • [[Agentic AI]] - AI that acts autonomously using tools
  • [[API]] - Application Programming Interface
  • [[Webhook]] - HTTP callback for events

Official Resources: