Wiring Up MCP: a Hand-Written JSON-RPC Client, Two Transports, and a Tool Namespace
Wire someone else's tools into your own agent: hand-write an MCP client without the official SDK, get both stdio and Streamable HTTP transports working, aggregate remote tools into the local tool list with a namespace, and route them through the same approval gate from day five.
Today's Goals
- Hand-write an MCP client that can initialize, list tools, and call tools
- Explain the fit and failure modes of the stdio and Streamable HTTP transports
- Safely aggregate remote tools into the local tool list, handling name collisions and trust boundaries
The first two weeks built a self-sufficient Agent, every tool written by us. Week three connects outside things, starting with other people's tools. When you finish, scroll back up and tick the three goals off.
Plain-Language Walkthrough
Borrowing another department's tool room
For fourteen days, everything mca could do grew in our own hands. Today handles a different request — the job needs a tool we do not have. Check the team notes for a convention before touching the code; check the ticket system for a matching ticket afterwards. Neither lives in this repository, and neither should be ours to implement.
In shop-floor terms: the new hire has their own toolbox, but the department next door keeps a tool room with better gear. Today's job is to hand them a key to that room, while saying what is inside, how to borrow it, and who is responsible when something goes wrong.
MCP, the Model Context Protocol, is the standard shape of that key. It specifies how a tool room labels its shelves, hands a tool over, and reports a problem, so that tools and clients written to the same standard recognize each other. Today we write the client half.
Why not the official SDK? The same reason as the past fourteen days — this course is about writing it yourself — plus one more today: the traps at the protocol layer are the ones an SDK hides, and they are where production breaks. Half a message, an unfinished page, a notification mistaken for a response, a callee's self-issued permission taken at face value — an SDK absorbs all four, so you never learn they exist.
Interview questions
If you hand-write an MCP client without the official SDK, which protocol details do you have to handle yourself?不用官方 SDK 手写一个 MCP 客户端,你必须自己处理哪些协议细节?
Common in ChinaCommon overseasBasic#json-rpc#mcp-client🔒 Unlock this chapter to see the answer keys.
When would you use the stdio transport versus Streamable HTTP, and how do their failure modes differ?stdio 与 Streamable HTTP 两种传输分别适合什么场景?它们的失败方式有什么不同?
Common in ChinaCommon overseasIntermediate#transports#stdio-vs-http🔒 Unlock this chapter to see the answer keys.
What governance would you put in place before aggregating third-party MCP server tools into your own agent?把第三方 MCP server 的工具聚合进自己的 Agent,你会加哪些治理措施?
Common in ChinaCommon overseasDeep dive#trust-boundary#tool-governance🔒 Unlock this chapter to see the answer keys.
