JSON-RPC 调用的结构
真实 MCP 消息中的 id、method 和 params。
JSON-RPC 调用的结构 是 CoddyKit 上的免费 MCP Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 MCP Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 MCP Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Open the Envelope
Let us dissect one real MCP message field by field. A JSON-RPC call is a small JSON object, and four keys carry all of its meaning.
The jsonrpc Version Tag
Every message starts with jsonrpc set to the string 2.0. It marks the dialect so both sides parse the rest the same way.
{"jsonrpc": "2.0"}The id Ties Things Together
The id is a number or string that labels a request. The matching response repeats it, so replies never get confused across many calls.
{"jsonrpc": "2.0", "id": 42}method Names the Action
The method string says what you want, like tools/call or resources/read. MCP groups methods with a slash, namespace before the verb.
{"method": "tools/call"}params Carries the Inputs
The params object holds the arguments for that method. For a tool call it names the tool and the values it should receive.
{"params": {"name": "add", "arguments": {"a": 2, "b": 3}}}A Full Request
Put the four keys together and you have a complete request. This one asks the server to run the add tool with two numbers.
{"jsonrpc": "2.0", "id": 42, "method": "tools/call",
"params": {"name": "add", "arguments": {"a": 2, "b": 3}}}params Is Optional
Some methods need no input at all. When that happens you simply omit params, as tools/list does when it just wants the full catalog.
{"jsonrpc": "2.0", "id": 5, "method": "tools/list"}Named, Not Positional
MCP always passes params as a JSON object with named keys, not a bare list. Names make the arguments self-documenting and order-independent.
The Response Mirror
The reply mirrors the request: same jsonrpc, same id, but method and params are gone. In their place sits a single result field.
{"jsonrpc": "2.0", "id": 42, "result": {"content": []}}Keys You Will See Most
Across MCP traffic you mostly meet tools/list, tools/call, resources/read, and prompts/get. Spot these methods and the intent jumps right out.
Read It at a Glance
Now any MCP line is readable: jsonrpc is the version, id pairs the reply, method is the verb, and params are the inputs. Four keys, full clarity.
Quick Check
In a JSON-RPC request, which field holds the arguments for the method?
Recap: Four Keys
You can now read any call: jsonrpc sets the version, id pairs the reply, method names the action, and params supplies its inputs. That is the whole anatomy.
常见问题解答
「JSON-RPC 调用的结构」课时是免费的吗?
是的 — 「JSON-RPC 调用的结构」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 MCP Academy 课程的其余内容,请升级到 CoddyKit PRO。 MCP Academy 课程共包含 4 节课。
「JSON-RPC 调用的结构」这节课中我会学到什么?
真实 MCP 消息中的 id、method 和 params。 你通过在浏览器中直接运行的动手代码来练习 MCP Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 MCP Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 MCP Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「JSON-RPC 调用的结构」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 MCP Academy 课中编写并运行代码吗?
能。每节 MCP Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。