MCP (Model Context Protocol)
Overviewβ
MCP (Model Context Protocol) is an open protocol used to connect AI assistants and system context (data sources, tools, environments). Released by Anthropic in November 2024, it aims to solve the standardization problem of integrating AI applications with external systems.
Official Document: https://modelcontextprotocol.io GitHub: https://github.com/modelcontextprotocol
Core conceptsβ
1. Definition of MCPβ
MCP is a client-server protocol that defines:
- How AI applications (clients) request data and operations
- How data sources/tools (server) expose their capabilities
- Standard format for message transmission
2. Architecture componentsβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ β
β β MCP Client β ββββββββΆβ MCP Server β β
β β (AI application) β ββββββββ (data source) β β
β ββββββββββββββββ ββββββββββββββββ β
β β β β
β βΌ βΌ β
β ββββββββββββββββ ββββββββββββββββ β
β β Claude Code β β File System β β
β β Cursor IDE β β Database β β
β β Cline β β API Service β β
β β Custom Application β β Git Repository β β
β ββββββββββββββββ ββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
MCP Core Competenciesβ
1. Resourcesβ
Resource is the data reading interface exposed by the server to the client.
// Resource example
{
"uri": "file:///Users/project/README.md",
"name": "Project README",
"description": "README file in the project root directory",
"mimeType": "text/markdown"
}
Common resource types:
| Type | URI Example | Description |
|---|---|---|
| Files | file:///path/to/file | Local File System |
| Git | git:///repo/file | Git repository content |
| Database | postgres://query | Database query results |
| API | https://api/data | HTTP API response |
| Memory | memory://variable | Runtime data |
2. Prompt word templates (Prompts)β
Prompt word template is a predefined prompt word provided by the server.
// Example of prompt word template
{
"name": "code-review",
"description": "code review prompt word",
"arguments": {
"file": "The path of the file to be reviewed",
"focus": "Review focus (security/performance/style)"
}
}
3. Toolsβ
Tools are executable functions exposed by the server.
// Tool example
{
"name": "execute_command",
"description": "Execute commands in the terminal",
"inputSchema": {
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "Command to be executed"
}
}
}
}
MCP transport layerβ
MCP supports multiple transmission methods:
1. STDIO (standard input/output)β
Applies to local inter-process communication:
# Start the MCP server through STDIO
claude-code mcp install my-server
my-server --stdio
2. SSE (Server-Sent Events)β
Applies to Local HTTP Communication:
// SSE connection
const client = new MCPClient({
url: "http://localhost:3000/sse",
transport: "sse"
});
3. Custom transmissionβ
Supports customizing transport layers such as WebSocket and gRPC.
Usage scenariosβ
1. MCP in Claude Codeβ
Claude Code natively supports MCP and can:
- Read project files via MCP
- Execute Git commands through MCP
- Access database via MCP
- Call external API via MCP
Configuration Example:
// .claude/mcp_config.json
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/project"]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"]
}
}
}
2. MCP in Cursor IDEβ
Cursor supports MCP extensions:
- Install MCP compatible server
- Cursor automatically discovers available resources
- Reference MCP resources in Chat
3. MCP in Clineβ
Cline (VS Code plugin) supports MCP:
- Get project context via MCP
- Execute build commands via MCP
- Access test results via MCP
MCP server exampleβ
File system serverβ
#Official file system server
npx -y @modelcontextprotocol/server-filesystem /path/to/directory
GitHub serverβ
# Official GitHub server
npx -y @modelcontextprotocol/server-github
Database serverβ
# PostgreSQL server
npx -y @modelcontextprotocol/server-postgres "postgresql://..."
Custom serverβ
// Customize MCP server
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
const server = new Server({
name: 'my-custom-server',
version: '1.0.0'
});
//Add resources
server.setRequestHandler(ListResourcesRequestSchema, async () => ({
resources: [
{
uri: 'custom://data',
name: 'custom data',
description: 'My custom data source'
}
]
}));
//Start the server
const transport = new StdioServerTransport();
await server.connect(transport);
Advantages of MCPβ
| Advantages | Description |
|---|---|
| Standardization | Unified protocol, no need to adapt separately for each AI application |
| Modular | Data sources are independent of AI applications and can be reused |
| Extensible | Supports custom transport layers and data sources |
| Security | Explicit permission control and data isolation |
| Openness | Open source protocol, community-driven development |
Comparison of MCP and other solutionsβ
| Solutions | MCP | LangChain Tools | OpenAI Function Calling |
|---|---|---|---|
| Degree of Standardization | β Open Protocol | β Vendor Specific | β Vendor Specific |
| Transport Layer | Multiple support | HTTP/RPC | HTTP |
| AI Compatibility | Multi-model | Mainstream LLM | OpenAI only |
| Community Ecology | Rapid growth | Mature | Mature |
| Learning Curve | Easy | Medium | Easy |
Quick startβ
1. Install Claude Code MCP integrationβ
# Install Claude Code CLI
npm install -g @anthropic-ai/claude-code
#Initialize MCP configuration
claude-code mcp init
2. Add MCP serverβ
# Add file system server
claude-code mcp install @modelcontextprotocol/server-filesystem
# Add GitHub server
claude-code mcp install @modelcontextprotocol/server-github
3. Use in Claude Codeβ
@mcp://filesystem/Users/project/src Please analyze the code structure in this directory
Reference resourcesβ
Official resourcesβ
Community Resourcesβ
Document updated: December 2025