MCP 协议规范详解:工具、资源与安全攻防全景

原标题:MCP Explained
58AI 研判分

这是一份对 Model Context Protocol(MCP)规范的结构化解读,覆盖 JSON-RPC 消息格式、初始化生命周期、stdio 与 Streamable HTTP 传输、OAuth 2.1 授权,以及服务端 Tools/Resources/Prompts 与客户端 Sampling/Elicitation/Roots 能力划分。文章还专门梳理了工具投毒、工具遮蔽、Token 透传、提示注入与诱导钓鱼等攻击面,并提及 Skills 扩展等演进方向。

报道正文

本文目录3 个章节

JSON-RPC has deprecated partsThe message format

  1. 1Request
  2. 2Result
  3. 3Error
  4. 4Notification
  5. 5Batch deprecated

LifecycleInitialize, operate, shut down

Transports has deprecated partsstdio and Streamable HTTP

Authorization has deprecated partsOAuth 2.1 for remote servers

Server features

ToolsFunctions the model can call

ResourcesData the app can read

PromptsTemplates the user picks

Client features

Sampling has deprecated partsThe server borrows the model

ElicitationThe server asks the user

RootsWhere the server may work

Utilities

ProgressProgress, cancel and logs

Tasks experimentalCall now, collect later

Not in the spec: harness techniques

Tool searchFind the right tool among thousands

CodemodeWrite a program, not 20 tool calls

Break it: attacks and defenses

Tool poisoningInstructions hidden in a tool

Tool shadowingOne server bends another's tool

PassthroughToken passthrough and the confused deputy

InjectionPrompt injection through tool results

PhishingElicitation phishing

Coming to MCP: extensions

Skills over MCP beta extensionAgent Skills served by a server

MCP Apps stable extensionInteractive UI from a tool

Server Cards beta extensionKnow a server before connecting

What's next

Spec 2026-07-28 ↗Stateless, no handshake, multi round-tripExtensions ↗Apps, Skills, Tasks, Server Cards, authSkills over MCP →Agent Skills as an MCP extension · lessonProgressive disclosure ↗Tool search and code mode, in the protocolRegistry ↗registry.modelcontextprotocol.io, in previewRoadmap ↗Next release planned for March 2027

Step 1 of 5

Request

Asks for something and expects exactly one response with the same id.

Network Sequence

Message flow 7 messages · 5 steps

Play Step Reset

#FromToMethodInfo
1MCP clientMCP servertools/listid 1 · list the tools
2MCP serverMCP clientresultid 1 · 1 tool
3MCP clientMCP servertools/calid 2 · tools/cal (typo)
4MCP serverMCP clienterror -32601id 2 · -32601 Method not found
5MCP serverMCP clientnotifications/tools/list_changedtools changed, no reply expected
6MCP clientMCP serverbatch [2]deprecatedarray of 2 requests
7MCP serverMCP clientbatch [2]deprecatedarray of 2 responses

JSON-RPC

The message format

Not in the MCP spec A harness implementation detail, not part of MCP. Nothing new on the wire: the client and servers still speak plain tools/list and tools/call.

Every MCP message is JSON-RPC 2.0. There are only three shapes: a request (has an id, wants an answer), a response (same id, carries a result or an error) and a notification (no id, no answer). Everything else in MCP is a method name on top of these.

| Encoding | UTF-8 JSON, one message per frame | | --- | | Shapes | request, response, notification | | Direction | both ways: servers send requests too | | Removed deprecated | batching: arrays of messages (2025-06-18) | | Error codes | -32700 parse, -32600 invalid, -32601 no method, -32602 bad params, -32603 internal | | Defined in | MCP spec 2025-11-25, Base protocol |

SpecBase protocol ↗JSON-RPC 2.0 ↗schema.ts ↗

What changes in 2026-07-28

  • Every result carries a required resultType: "complete" or "input_required".
  • Servers no longer send requests to clients: they return input_required and the client retries with the answers (multi round-trip).
  • Resource not found moves from -32002 to -32602; new MCP codes -32020 to -32022.

Changelog ↗

Message

tools/list 58 B

MCP client → MCP server · Request · #1

{ "jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {} }id String or integer, never null. Not reused by the sender within the session.method What to do. MCP defines the method names.params Optional arguments object.

MCP spec 2025-11-25. Token counts are illustrative. Made by Runlayer, the operating layer for AI.