What is MCP

Model Context Protocol (MCP) is an open-source communication protocol developed by Anthropic. It provides a standardized mechanism for AI assistants (especially Claude) to securely and efficiently connect with external data sources and tools.

Why Do We Need MCP?

Traditional AI assistants relied solely on knowledge learned during training. However, real-world data is constantly updated, and organization-specific information exists. MCP was created to bridge this "knowledge gap".

For example, it becomes possible to retrieve the latest sales data from internal databases, read the latest code from GitHub repositories, or reference Slack conversation history.

Basic Mechanism

MCP adopts a "client-server" architecture. AI assistants (clients) and MCP servers communicate using a standard communication protocol called JSON-RPC 2.0.

💡 Key Point

JSON-RPC 2.0 is a simple and lightweight communication protocol. It enables more efficient request-response communication similar to HTTP.

Architecture

graph TB subgraph client["AI Client"] A[Claude/Cursor/Zed] end subgraph server["MCP Server"] B[Server Process] C[Resources] D[Tools] E[Prompts] end subgraph external["External Systems"] F[Database] G[APIs] H[File System] end A -.->|"JSON-RPC 2.0"| B B --> C B --> D B --> E B -.-> F B -.-> G B -.-> H classDef clientClass fill:#3b82f6,stroke:#2563eb,color:#fff,stroke-width:2px classDef serverClass fill:#6366f1,stroke:#4f46e5,color:#fff,stroke-width:2px classDef externalClass fill:#8b5cf6,stroke:#7c3aed,color:#fff,stroke-width:2px classDef processClass fill:#10b981,stroke:#059669,color:#fff,stroke-width:2px class A clientClass class B processClass class C,D,E serverClass class F,G,H externalClass

Three Core Features of MCP

MCP provides AI assistants with three important features:

1. Resources

A feature that provides external data in "read-only" mode. AI assistants can read file contents or retrieve information from databases, but cannot make changes.

Example:
Read project README file
Search information from customer database
Reference API documentation

2. Tools

A feature that executes "actions" in external systems. This allows AI assistants to not only provide information but actually perform tasks.

Example:
Create a pull request on GitHub
Send a message to Slack
Add a record to database

3. Prompts

A feature that provides "templates" to customize AI assistant behavior. You can adjust how the AI responds based on specific contexts.

Example:
Detailed instructions for code review
Coding conventions for specific projects
Explanations of organization-specific terms and abbreviations

Actual Communication Flow

Let's see how AI assistants and MCP servers actually communicate.

sequenceDiagram participant C as AI Client participant S as MCP Server participant E as External System rect rgb(59, 130, 246, 0.1) note right of C: Initialization Phase C->>+S: initialize S-->>-C: capabilities end rect rgb(99, 102, 241, 0.1) note right of C: Discovery Phase C->>+S: tools/list S-->>-C: available tools end rect rgb(139, 92, 246, 0.1) note right of C: Execution Phase C->>+S: tools/call S->>+E: execute action E-->>-S: result S-->>-C: tool result end

Understanding Through Actual Code Examples

Based on the explanations so far, let's look at an example of actually implementing an MCP server. Below is an example of a simple MCP server that retrieves data from a database.

// server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server({
  name: 'example-server',
  version: '1.0.0'
}, {
  capabilities: {
    tools: {}
  }
});

// Define a tool
server.setRequestHandler(ListToolsRequestSchema, async () => ({
  tools: [{
    name: 'get_data',
    description: 'Fetch data from database',
    inputSchema: {
      type: 'object',
      properties: {
        query: { type: 'string' }
      },
      required: ['query']
    }
  }]
}));

// Handle tool execution
server.setRequestHandler(CallToolRequestSchema, async (request) => {
  if (request.params.name === 'get_data') {
    // Execute database query
    const result = await db.query(request.params.arguments.query);
    return {
      content: [{
        type: 'text',
        text: JSON.stringify(result)
      }]
    };
  }
});

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

🔍 Code Explanation

  • Server class: Provides basic MCP server functionality
  • ListToolsRequestSchema: Returns a list of available tools
  • CallToolRequestSchema: Actually executes the tool
  • StdioServerTransport: Communication using standard I/O

Configuration in Claude Desktop

To use the created MCP server with Claude Desktop, you need to register it in the configuration file.

// ~/.claude_desktop_config.json
{
  "mcpServers": {
    "example": {
      "command": "node",
      "args": ["/path/to/server.js"]
    }
  }
}

✅ Configuration Points

With this configuration, when you start Claude Desktop, the MCP server will also start automatically, allowing Claude to use the tools.

Rich Development Language Support

MCP supports many programming languages, so you can develop in the language you are familiar with:

  • TypeScript / JavaScript
  • Python
  • Go
  • Rust
  • C#
  • Ruby
  • Java
  • Kotlin
  • Swift
  • PHP

Supported Clients

  • Claude Desktop
  • Cursor
  • Zed
  • Replit
  • Cody