How MCP was invented: from homemade scripts to Anthropic’s protocol

Серверные стойки соединены светящимися линиями данных — протокол MCP

In November 2024, Anthropic released the open MCP protocol (Model Context Protocol) — a standard under which an application gives a language model access to external tools. By the spring of 2025 everyone was talking about it, the specification had been updated several times, and the project had gained official documentation and a registry of servers. The author of the Habr publication spent that same period assembling his own version of the same protocol in two weeks — honestly, without knowing the ready standard existed. The result is a chronicle of how MCP was invented from scratch, and the main takeaway: it pays to first build your own bicycle within a timebox and only then read the specification — other people’s solutions read not as an instruction but as an explanation.

Why reinvent the wheel when a ready protocol exists

The author deploys AI assistants in companies and works with OpenWebUI. The idea of the exercise is simple: trying to invent a protocol yourself shows which problems you will really have to solve. With a timebox — half a day, at most a day. Then a comparison with the existing standards by function, not by name: side by side ended up your own implementation, JSON-RPC, whose specification is about twenty years old, and MCP. This order is faster and more useful than a week of reading documentation: after it, every decision in the specification looks like an answer to a specific pain you have just felt on your own build.

Stage one: tools in a browser tab

In early 2025 the assistant knew how to answer but not to act: it could not check bonus points, find an order or create a request. The first solution was Python functions with a docstring in the “Tools” section of OpenWebUI. The demo took fifteen minutes, and that was where the advantages ended. The code lived in the web interface: not in git, not in CI, with no review. Dependencies clashed inside the container, secrets sat right in the code, a long operation blocked the chat, nothing could be reused between instances, and there was no audit at all.

Stage two: ordinary web services

The tools were moved into separate services as endpoints: GET /loyalty/balance?card=1234 for the balance, GET /orders/1042/status for order status, POST /payments/1042/confirm for payment confirmation, GET /delivery/slots?date=2025-06-01 for delivery slots. At first it was twelve lines; a month later — twenty endpoints. The prompt bloated and the model got confused: duplicates like get_order_status, get_order_info, get_order_state and get_order_history appeared in the descriptions, and the model could not pick one of the four. Adding a tool turned into a ritual: an endpoint, an OpenAPI update, an update of the description in the prompt, a possible deploy.

Stage three: one endpoint for everything

The logical next step was POST /functions with a body of {functionName, functionParams}. One URL, one token, logs and limits in one place. But the model produced a new list of problems: an aging list of functions in the prompt, type confusion (“123” instead of 123, double serialization), no identifier for matching a request with its response, inconsistent error formats and silent client breakages. At this point a diagnosis was born that everyone should memorize:

I built a transport and called it a protocol.

A comparison with JSON-RPC and MCP by function

The search turned up two candidates: JSON-RPC, alive for about twenty years, and MCP. The comparison by function, not by name, produced the following picture.

My homemade “protocol”JSON-RPC 2.0MCP
One URL for everythingNot specifiedStreamable HTTP or stdio
functionNamemethodmethod: tools/call + name
functionParamsparamsparams.arguments
Nothingidid plus a session
Own error stringsCodes -32700…-32603The same codes plus its own
A list of functions in the promptNonetools/list
Parameter descriptions as textNoneinputSchema (JSON Schema)
NoneNoneinitialize and version negotiation
NoneNoneresources, prompts, notifications

The key discovery: MCP is a protocol for the host application, not for the model. The model does not speak MCP: it calls functions, and the host turns that into the method tools/call. The author invented tool calling but did not invent discovery (tools/list), resources (resources) or prompts (prompts) — and those are exactly what separate a transport from a protocol.

The implementation: the same protocol on NiFi

For the build the author took Apache NiFi, which he has worked with for about ten years. Five reasons: Data Provenance, where every call becomes a FlowFile with a full history; back pressure, that is, queues with thresholds on count and volume; retries with penalties when an external API goes down; routing instead of code through RouteOnAttribute by method and function name; and a familiar stack that saves weeks. The flow is linear: HandleHttpRequest accepts POST /mcp, EvaluateJsonPath extracts method, id and params.name, RouteOnAttribute splits off initialize, tools/list, tools/call and ping, the InvokeHTTP and ExecuteScript branches do the work, the response is assembled with jsonrpc and id, and HandleHttpResponse returns 200 and application/json.

A tool call looks like an ordinary JSON-RPC message:

{"jsonrpc": "2.0", "id": 17, "method": "tools/call", "params": {"name": "get_customer_balance", "arguments": {"card": "1234"}}}

The double facade was needed because OpenWebUI spoke OpenAPI back then: for MCP clients there was the /mcp endpoint, for classic consumers — /functions. The Open WebUI team released the mcpo bridge at about the same time — the author learned of it later than he wrote his own dispatcher in Groovy with JsonSlurper and a switch on method. The tool catalog was described in JSON format with inputSchema: for get_customer_balance the card field is required and store is optional; an unknown method returned the -32601 error.

The pitfalls the tutorials keep quiet about

The list is short, but every item costs a day of debugging. A JSON-RPC error does not turn into an HTTP 500: the client receives 200 and an error code in the body. id has to be carried through every branch of the flow. arguments suffer from double serialization — cured by validation against inputSchema. An unknown tool must return an honest -32601 error, not an empty success response. HandleHttpResponse must stand on every branch, otherwise the client hangs until the timeout and holds memory. Provenance stores personal data — masking and a retention period are required. A retry can execute an action twice — idempotency keys are required. And the main thing: the description of a tool is prompt engineering — the wording decides whether the model picks the right function.

What the homemade solution lacked

Streaming: HandleHttpRequest is request-response, and SSE and Streamable HTTP in full are unavailable. Real sessions: initialize is served, but the mode is stateless. Proper authorization per the specification: an internal network and a token instead of OAuth. Clustering: the response must come back to the same node. Low latency: a FlowFile for every call. Script versioning: the code lives in the processor’s UI. This is not exotic stuff but basic production requirements — and that is exactly why the mature standard proved more useful than the homemade contraption.

What this means for those building agents

Three takeaways carry beyond this story. First: one endpoint is only a transport — the value of a protocol lies in the tool catalog, the parameter schemas and predictable errors. Second: MCP is a protocol for the application, and you should not expect the model to “understand” it on its own. Third: the timebox rule works — a bicycle assembled in a day explains the shape of the standard better than reading the spec. It is worth starting with the official MCP documentation; agent practice is easier to build through our Start with Agents hub; and among the protocol’s clients today is the terminal harness Claude Code, whose Claude Code repository on GitHub is open.

MCP cheat sheet for agent builders

The gist for those who skipped the story: MCP shipped in November 2024, by the spring of 2025 the specification had been updated several times and an official registry of servers had appeared. The technical foundation is JSON-RPC: the tools/call method with params.arguments, an id field for matching requests with responses, and error codes from -32700 to -32603. The client receives the tool catalog through tools/list, parameters are described by the inputSchema schema in JSON Schema, and initialize negotiates the version. The protocol also has resources and prompts. The practical meaning: if your “protocol” is one endpoint with a list of functions in the prompt, you have a transport; add discovery, schemas and predictable error codes — and you will have almost reproduced MCP.

Like this post? Please share to your friends:
11AI - Your Free LLM
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: