Skip to main content

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:

TypeURI ExampleDescription
Filesfile:///path/to/fileLocal File System
Gitgit:///repo/fileGit repository content
Databasepostgres://queryDatabase query results
APIhttps://api/dataHTTP API response
Memorymemory://variableRuntime 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​

AdvantagesDescription
StandardizationUnified protocol, no need to adapt separately for each AI application
ModularData sources are independent of AI applications and can be reused
ExtensibleSupports custom transport layers and data sources
SecurityExplicit permission control and data isolation
OpennessOpen source protocol, community-driven development

Comparison of MCP and other solutions​

SolutionsMCPLangChain ToolsOpenAI Function Calling
Degree of Standardizationβœ… Open Protocol❌ Vendor Specific❌ Vendor Specific
Transport LayerMultiple supportHTTP/RPCHTTP
AI CompatibilityMulti-modelMainstream LLMOpenAI only
Community EcologyRapid growthMatureMature
Learning CurveEasyMediumEasy

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