MCP(Model Context Protocol) 是由 Anthropic 推出的开放标准,允许 AI 应用通过统一的接口连接外部工具和数据——而不是为每个应用编写定制的集成。可以将其视为模型与外部世界之间的通用适配器。
Client 和 server
text
MCP SERVER → exposes capabilities to the model:
- TOOLS → actions the model can call (send_email, create_issue, search_files)
- RESOURCES → data the model can read (a file, a Drive doc, a DB row)
- PROMPTS → reusable prompt templates the server offers
MCP CLIENT → the AI app (Claude Desktop, Claude Code, an IDE) that connects to servers
TRANSPORT → stdio (local process) or HTTP (remote), speaking JSON-RPC both ways
关键优势:每个工具提供商编写一个 MCP server,任何 MCP 兼容的 client 都可以使用它。你添加一个 Gmail server、一个 Drive server、一个 Jira server——模型就可以调用所有这些工具,无需为每个应用手动编写定制集成。
一个小的配置和流程
jsonc
// The client config registers servers; the model then sees their tools
{
"mcpServers": {
"gmail": { "command": "npx", "args": ["@org/mcp-gmail"] }, // local, stdio
"jira": { "url": "https://mcp.acme.com/jira" } // remote, HTTP
}
}
text
FLOW:
1. Client starts/connects to each server, asks "what tools do you have?"
2. Server replies with tool schemas (name, description, params) via JSON-RPC
3. User: "file a Jira bug for the login crash" → model picks the jira create_issue tool
4. Client calls the tool on the server → server hits the Jira API → returns the result
5. Model uses the result in its answer
由于发现和调用通过 JSON-RPC 进行标准化,模型在连接时学习每个 server 的工具——应用本身无需编写每个工具的代码。
为什么这很重要
在 MCP 出现之前,每个 AI 到工具的集成都是一次性的:定制代码、定制认证、定制维护,每个应用和每个 AI 产品都要重复。MCP 用一个协议解决了这个 N×M 的扩展问题——工具作者发布一个 server,每个兼容的 client 都可以免费获得该集成。正是这种标准化使得为助手提供对 Gmail、Drive、Jira 和您自己的内部系统的真正访问成为可能,而无需每次都重新构建基础设施。
