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
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.
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