MCP

Anthropic 提出的开放协议,让 AI 用统一的方式接外部工具和数据源,不用为每个模型各写一遍

MCP(Model Context Protocol,模型上下文协议)是 Anthropic 于 2024 年底开源的一套开放协议,用来规范 AI 应用怎么连接外部的工具和数据源。它解决的是一个很土但很real的工程问题:N 个模型客户端 × M 个数据源 = N×M 套对接代码

有了统一协议之后,数据源方只需要实现一次 MCP Server,任何支持 MCP 的客户端都能用;客户端方只需要实现一次 MCP Client,就能接上生态里所有 Server。N×M 降成 N+M。

三个角色

  • Host / Client:发起方,一般是 AI 应用本身(编程助手、聊天客户端)。它负责把可用的能力告诉模型,并在模型要求调用时转发请求。
  • Server:能力提供方。包一个数据库、一个 API、一个文件系统,按协议暴露出去。
  • 传输层:本地跑用标准输入输出(stdio),远程跑走 HTTP。

Server 能暴露三类东西

  • Tools(工具):模型可以主动调用的动作,比如查数据库、建工单。有副作用,通常需要用户授权。
  • Resources(资源):可以被读取的数据,比如文件内容、表结构。由应用决定放多少进上下文。
  • Prompts(提示模板):预置好的交互模板,让用户一键触发某个复杂流程。

为什么它重要

在 MCP 之前,每个 AI 应用的工具生态是封闭的——你为某个产品写的插件,换个产品就白写。MCP 把这层做成了公共协议,类似当年 LSP 之于编辑器:LSP 出现前每个编辑器要为每种语言各写一套支持,出现后语言方写一次、所有编辑器受益。

到 2025 年,主流 AI 客户端和多家模型厂商陆续支持了 MCP,它事实上成了这一层的通用接口。

安全上必须知道的

MCP Server 拿到的是真实权限——能读的文件、能调的接口、能改的数据,都是真的。几个必须守住的点:

  • 只接可信来源的 Server。一个恶意 Server 可以在工具描述里塞入提示注入,诱导模型做出格的操作。
  • 最小权限。给 Server 配的凭据要按需授权,别直接给管理员 token。
  • 有副作用的工具要有确认环节,不要让模型自由触发删除、支付、对外发送。

常见误解

"MCP 是 Anthropic 家的东西,只能配 Claude 用"——不是。它是开源协议,规范和 SDK 公开,任何模型和客户端都能实现,实际上也已经被多家采用。

"MCP 让模型变强了"——不是。它不改变模型能力,只是把"怎么把工具接上去"这件事标准化了。

英文原文解释(Dictionary of AI Coding)

Model Context Protocol. A protocol for plugging external tool servers into a harness — how an agent gets tools beyond what the harness ships with. The agent never "calls MCP"; it calls a tool, and the harness happens to have gotten that tool from an MCP server. Also exposes resources (read-only data) and prompts (reusable templates), but tool provision is the primary use.

The protocol solves an integration problem. Without a standard, every harness would need its own Linear integration, its own Slack integration, its own database integration — written and maintained separately for each. With MCP, the integration is written once as a server, and any MCP-compatible harness can use it. The harness connects to the server, the server advertises what tools it offers, and those tools become available to the agent alongside the built-in ones.

The cost is paid in context. Every tool a server advertises arrives as a definition — name, description, parameter schema — and the model can only call tools it knows about. The naive approach loads every definition into the context window up front: install a few generous servers and a session starts with thousands of tokens of tool schemas before you've typed anything, spending attention budget on tools the task will never use.

Many harnesses now mitigate this with tool search: instead of the full definitions, the context holds a context pointer to the available tools — the agent searches for a tool by name or purpose and loads its definition only when it needs it. If your harness doesn't do this, the up-front cost still applies, and it's worth enabling only the servers a project actually needs.

什么时候会用到

给 AI 应用接内部系统时的默认选型;也是判断一个 AI 客户端生态开放程度的标志。

例句

  • 这套内部 API 包成一个 MCP Server 吧,以后换客户端不用重写。
  • 别随便装来路不明的 MCP Server,工具描述里能藏提示注入。
  • MCP 不是 Claude 专用的,是开放协议,别家客户端也在支持。

别混淆

别把 MCP 和 Function Calling 混为一谈。Function Calling 是模型输出调用请求的能力;MCP 是规定这些工具怎么被发现、连接和传输的协议,一个在模型层,一个在系统层。

相关词