MCP · 从协议规范到 Server 实现MCP · From Protocol Spec to Server Implementation.
Model Context Protocol 是工具调用的标准化层 —— 一次实现,所有客户端都能用。Model Context Protocol is the standardization layer for tool use — implement once, every client can use it.
你给研究助手焊了 web_search、fetch_page —— 但只有它能用,换个客户端就得重写一遍。MCP(Model Context Protocol)是中间那一层标准:把工具从你的代码里解耦出来,实现一次,任何 MCP 客户端都能接。这一章讲它解决什么、怎么把研究助手的工具做成 server,以及接别人的 server 有什么风险。You welded web_search and fetch_page into the research assistant — but only it can use them; switch clients and you rewrite. MCP (the Model Context Protocol) is the standard layer in between: it decouples tools from your code so you implement once and any MCP client can connect. This chapter covers what it solves, how to turn the assistant's tools into a server, and the risk of connecting someone else's.
— I
MCP 解决的是「N 个工具 × M 个客户端」的重复劳动MCP Solves the 'N Tools × M Clients' Duplication.
工具焊进一个 agent,只有它能用;做成一个 MCP server,任何客户端都能接。A tool welded into one agent is usable only by it; built as an MCP server, any client can connect.没有 MCP,每个工具要为每个客户端(你的 agent、Claude、ChatGPT、VS Code、Cursor)各写一遍适配 ——N 个工具乘 M 个客户端的重复劳动。MCP 是中间的标准层,官方比喻是「AI 应用的 USB-C」:一次实现,到处接。1注 1Note 1Model Context Protocol · 官方文档 —— 连接 AI 应用与外部系统的开放标准,官方比喻为「AI 应用的 USB-C」;一次实现,任何 MCP 客户端(Claude、ChatGPT、VS Code、Cursor 等)都能接(build once, integrate everywhere)。截至 2026-05。Model Context Protocol · official docs — an open standard connecting AI apps to external systems, framed as 'a USB-C port for AI applications'; build once and any MCP client (Claude, ChatGPT, VS Code, Cursor) connects. As of 2026-05.Without MCP, every tool needs an adapter for every client (your agent, Claude, ChatGPT, VS Code, Cursor) — N tools times M clients of duplication. MCP is the standard layer in between, framed as 'a USB-C port for AI applications': build once, integrate everywhere.1注 1Note 1Model Context Protocol · 官方文档 —— 连接 AI 应用与外部系统的开放标准,官方比喻为「AI 应用的 USB-C」;一次实现,任何 MCP 客户端(Claude、ChatGPT、VS Code、Cursor 等)都能接(build once, integrate everywhere)。截至 2026-05。Model Context Protocol · official docs — an open standard connecting AI apps to external systems, framed as 'a USB-C port for AI applications'; build once and any MCP client (Claude, ChatGPT, VS Code, Cursor) connects. As of 2026-05.但 MCP 不是免费的抽象。如果你的工具只服务你自己一个 agent、永远不外接,直接 function calling(第三章)更简单。MCP 的价值,只在「同一个工具要被多个客户端用」或「你想接别人已经写好的 server」时才兑现。But MCP isn't a free abstraction. If a tool serves only your one agent and never anything else, plain function calling (chapter 3) is simpler. MCP pays off only when 'the same tool must serve multiple clients' or 'you want to plug into a server someone already wrote.'
— II
一个 MCP server 暴露三种东西An MCP Server Exposes Three Things.
MCP server 给客户端的不只是工具,是三类原语:tools(可执行动作)、resources(可读数据)、prompts(预制模板)。An MCP server gives clients more than tools — three primitives: tools (executable actions), resources (readable data), prompts (reusable templates).tools 是模型可调用的动作(和第三章的 function 一一对应),resources 是客户端按 URI 取的可读数据,prompts 是可复用的提示模板。规范里最吃重的区分是「谁来控制」:tools 由模型控制、resources 由应用控制、prompts 由用户控制 —— 三者面向不同的发起方。传输有两种:stdio(本地子进程)和 streamable HTTP(远程,已取代旧的 HTTP+SSE)。2注 2Note 2MCP 规范 · 架构 —— server 暴露三种原语,按「谁控制」区分:tools(模型控制的可执行动作)、resources(应用控制的可读数据)、prompts(用户控制的预制模板);基于 JSON-RPC 2.0;传输用 stdio(本地)与 streamable HTTP(远程,已取代旧 HTTP+SSE)。spec 按日期版本化,最新修订 2025-11-25。截至 2026-06。MCP spec · architecture — a server exposes three primitives, split by who controls each: tools (model-controlled executable actions), resources (application-controlled readable data), prompts (user-controlled templates); built on JSON-RPC 2.0; transports are stdio (local) and streamable HTTP (remote, which replaced the older HTTP+SSE). The spec is date-versioned; latest revision 2025-11-25. As of 2026-06.用官方 Python SDK,实现一个 server 就是注册这几样:tools are actions the model can call (one-to-one with chapter 3's functions), resources are readable data the client fetches by URI, and prompts are reusable templates. The spec's load-bearing distinction is who controls each: tools are model-controlled, resources application-controlled, prompts user-controlled — three different initiators. Two transports: stdio (a local subprocess) and streamable HTTP (remote, which replaced the older HTTP+SSE).2注 2Note 2MCP 规范 · 架构 —— server 暴露三种原语,按「谁控制」区分:tools(模型控制的可执行动作)、resources(应用控制的可读数据)、prompts(用户控制的预制模板);基于 JSON-RPC 2.0;传输用 stdio(本地)与 streamable HTTP(远程,已取代旧 HTTP+SSE)。spec 按日期版本化,最新修订 2025-11-25。截至 2026-06。MCP spec · architecture — a server exposes three primitives, split by who controls each: tools (model-controlled executable actions), resources (application-controlled readable data), prompts (user-controlled templates); built on JSON-RPC 2.0; transports are stdio (local) and streamable HTTP (remote, which replaced the older HTTP+SSE). The spec is date-versioned; latest revision 2025-11-25. As of 2026-06. With the official Python SDK, implementing a server is just registering these:
一个最小 MCP server(Python SDK,stdio)A minimal MCP server (Python SDK, stdio)
别把所有东西都做成 tools。三类原语各有用途 —— 动作是 tools,数据是 resources,模板是 prompts。3注 3Note 3MCP Python SDK(modelcontextprotocol/python-sdk)—— 官方 SDK,FastMCP 用 @mcp.tool() 注册工具、mcp.run() 起服务。引用发布版本而非 main。MCP Python SDK (modelcontextprotocol/python-sdk) — the official SDK; FastMCP registers tools with @mcp.tool() and serves with mcp.run(). Cite a released version, not main.混着用,客户端就不知道该怎么把它们呈现给用户。Don't make everything a tool. The three primitives have distinct uses — actions are tools, data are resources, templates are prompts.3注 3Note 3MCP Python SDK(modelcontextprotocol/python-sdk)—— 官方 SDK,FastMCP 用 @mcp.tool() 注册工具、mcp.run() 起服务。引用发布版本而非 main。MCP Python SDK (modelcontextprotocol/python-sdk) — the official SDK; FastMCP registers tools with @mcp.tool() and serves with mcp.run(). Cite a released version, not main. Mix them up and the client won't know how to present them to the user.
— III
接别人的 server,风险和接第三方代码一样Connecting Someone's Server Is Like Running Third-Party Code.
MCP 最大的红利是生态 —— 一堆现成 server 可接;但接一个 server,等于让它进入你的信任边界。MCP's biggest dividend is its ecosystem — many ready-made servers to connect; but connecting one lets it into your trust boundary.一个第三方 MCP server 能读你给它的 resources、能执行它声明的 tools。接之前看清楚:它要什么权限、跑在哪(本地 stdio 子进程 vs 远程 HTTP)。远程 server 还多两件事 —— 鉴权和数据出境。1注 1Note 1Model Context Protocol · 官方文档 —— 连接 AI 应用与外部系统的开放标准,官方比喻为「AI 应用的 USB-C」;一次实现,任何 MCP 客户端(Claude、ChatGPT、VS Code、Cursor 等)都能接(build once, integrate everywhere)。截至 2026-05。Model Context Protocol · official docs — an open standard connecting AI apps to external systems, framed as 'a USB-C port for AI applications'; build once and any MCP client (Claude, ChatGPT, VS Code, Cursor) connects. As of 2026-05.这和「装一个第三方 skill」是同一类风险:你在把执行权交给别人的代码。A third-party MCP server can read the resources you give it and execute the tools it declares. Before connecting, be clear: what permissions it wants, and where it runs (a local stdio subprocess vs remote HTTP). Remote servers add two more things — authentication and data leaving your machine.1注 1Note 1Model Context Protocol · 官方文档 —— 连接 AI 应用与外部系统的开放标准,官方比喻为「AI 应用的 USB-C」;一次实现,任何 MCP 客户端(Claude、ChatGPT、VS Code、Cursor 等)都能接(build once, integrate everywhere)。截至 2026-05。Model Context Protocol · official docs — an open standard connecting AI apps to external systems, framed as 'a USB-C port for AI applications'; build once and any MCP client (Claude, ChatGPT, VS Code, Cursor) connects. As of 2026-05. This is the same class of risk as installing a third-party skill: you're handing execution to someone else's code.判断很简单:自己的数据和动作 → 自己写 server,跑本地 stdio;成熟的公共服务(GitHub、Notion 的官方 server)→ 接官方的;来历不明的 server → 当第三方代码审,或者别接。这条信任线,第 9 章会再系统地画一次。The call is simple: your own data and actions → write your own server, run it on local stdio; mature public services (the official GitHub or Notion servers) → use the official one; servers of unknown origin → audit them as third-party code, or don't connect. Chapter 9 draws this trust line systematically.动手 · 把一个工具变成 server,再审一个别人的 server:Hands-on · turn one tool into a server, then audit someone else's:
01
把研究助手的一个工具包成 MCP serverWrap one of the assistant's tools as an MCP server
用 stdio 起一个最小 server,从一个 MCP 客户端(Claude Desktop 或你的 agent)连上它,跑通一次调用。Stand up a minimal stdio server, connect it from an MCP client (Claude Desktop or your agent), and complete one call.
02
审一个你想用的第三方 serverAudit a third-party server you'd want
找一个你真想接的公共 server,列清楚:它声明了哪些 tools / resources、跑在本地还是远程、要不要交出数据。Pick a public server you'd actually use, and list it out: which tools / resources it declares, local or remote, and whether it requires handing over data.
03
给它一个信任判断Give it a trust verdict
据上面的审计写一句话结论:自己写、接官方、还是不接 —— 并说清你为什么信它。From that audit, write a one-line verdict: write your own, use the official, or don't connect — and say why you'd trust it.
焊进一个 agent,只你能用;
做成一个 server,谁都能接。.
Welded into one agent, it's yours alone;
built as a server, anyone connects..
Aklman Library
— 讨论Discussion
讨论Discussion.
评论区初始化中…Initializing comments…
01 / 01
没有匹配结果No matches.
换个关键词,或按 Esc 回到页面Try another keyword, or press Esc to return