MCP (Model Context Protocol) is one standard way for an AI app to use tools. Build a tool once as an MCP server, and any AI app that speaks MCP can use it: your own Java agent, Claude Desktop, VS Code, OpenCode. People call it “USB-C for AI tools”, and that’s a fair picture: one port, any device.
This article explains MCP from the ground up, in the order that makes it click:
- Why MCP exists (the problem).
- What it looks like (host, client, server).
- How it talks underneath (RPC, then JSON-RPC).
- One full trip, from “what tools do you have?” to the answer.
No code needed to follow along. When you want to build one, the next article is MCP Hello World in Java.
The problem: every agent rebuilds every tool
In an AI agent, the LLM can’t read files or call GitHub by itself. It asks for a tool, and your code runs it. That’s tool calling: the LLM decides, your code does.
Now imagine three agents. Different jobs, but all three need the same three things: files, GitHub and a database. Without a standard, each agent gets its own copy of the tool code. That’s 3 agents × 3 tools = 9 pieces of code (the picture at the top of this page):
- The same work is done three times.
- GitHub changes its API? You fix it in three places.
- A new tool? You change every agent.
MCP’s idea is simple: take the tool code out of the agents. Each tool becomes its own small program, an MCP server, built once. Each agent gets one MCP client, which the SDK gives you. Any client can talk to any server, because they all speak the same protocol.
The big picture: host, client, server
Every MCP setup has the same three roles.
| Role | What it is | Example |
|---|---|---|
| Host | The AI app. It runs the agent loop and talks to the LLM. | Our Java agent, Claude Desktop, VS Code |
| MCP client | A small connector inside the host. One client per server. It asks the server what it offers and calls it. | Comes with the MCP SDK; you don’t write it |
| MCP server | A small program that wraps a real system (your disk, GitHub) and offers its tools. | files-server with read_file, list_files, save_file |
Think of a laptop: the host is the laptop, the client is the port, the server is the device you plug in.
One thing surprises most people: the LLM never talks to an MCP server. It doesn’t even know MCP exists. It sees a list of tools, exactly as before. The host does all the MCP talking.
(Servers can also offer resources, which is data to read, and prompts, which are ready-made templates. Tools are what you’ll use first, so this article sticks to tools.)
Under the hood, part 1: RPC
So a client asks a server, “please run read_file”. How does a call travel from one program to another? This is an old problem, and it has a name: RPC, Remote Procedure Call.
The idea: call a function that lives on another computer, and make it look like a normal call.
Your code writes subtract(42, 23) and gets 19. Behind the scenes, four things happen: pack the call (name + inputs) into a message, send it, run it on the other side, and send the answer back. It’s like a restaurant: you order, the kitchen cooks, the plate comes to your table, and you never walk into the kitchen.
RPC is an idea, and people have built it many ways over the years:
| Way | Year | Message format | Good | Not so good |
|---|---|---|---|---|
| Java RMI | 1997 | Java objects | Feels like normal Java | Both sides must be Java |
| XML-RPC | 1998 | XML over HTTP | Any language | Wordy |
| JSON-RPC | 2005, v2.0 in 2010 | JSON, over any transport | Small, readable, any language | Slower than binary |
| gRPC | 2015 | Binary (Protocol Buffers) over HTTP/2 | Very fast | Not readable by eye; needs a .proto file |
MCP chose JSON-RPC 2.0. Here’s why it fits so well:
- Easy to read. It’s plain JSON, so to debug you just look at the message.
- Any language. Java, Python and TypeScript all read JSON, so you can write servers in any of them.
- Any transport. The same message works through a local pipe or over HTTP.
- Tiny spec. A few pages. Easy to learn, easy to build.
- AI already speaks JSON. LLM tool calls are JSON too.
- Proven. Code editors’ Language Server Protocol runs on JSON-RPC, and MCP took ideas from it.
So MCP didn’t invent a new message format. It reused a proven one.
Under the hood, part 2: JSON-RPC in three minutes
You only need three facts about JSON-RPC.
1. A request has four fields.
{ "jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1 }
In plain English: “Please run subtract with 42 and 23. This is request number 1.”
| Field | Meaning |
|---|---|
jsonrpc |
The version. Always exactly "2.0". |
method |
The name of the function to run. |
params |
The inputs (optional). A list by position, or an object by name. MCP always uses by name. |
id |
The request number. The answer comes back with the same id. |
2. A response has a result or an error, never both, and the same id.
{ "jsonrpc": "2.0", "result": 19, "id": 1 }
{ "jsonrpc": "2.0", "error": { "code": -32601, "message": "Method not found" }, "id": 1 }
The spec reserves five standard error codes:
| Code | Name | When |
|---|---|---|
| -32700 | Parse error | The JSON itself is broken |
| -32600 | Invalid Request | Valid JSON, but not a valid request |
| -32601 | Method not found | No such method |
| -32602 | Invalid params | Wrong inputs |
| -32603 | Internal error | It broke on the server side |
If the server can’t even read the id (because the JSON is broken), it answers with "id": null.
3. The id is what makes it work. A message without an id is a “notification”.
The client can send several requests without waiting. Answers can come back in any order, and each one lands in the right slot because it carries its id. A message without an id is a notification, meaning “just so you know”. The server must not reply to it.
(JSON-RPC also allows a batch, several requests in one array. MCP removed batching in its 2025-06-18 version, so you won’t use it with MCP.)
The “aha” moment: an MCP message is a JSON-RPC message
Now put a plain JSON-RPC request next to a real MCP message, where our agent asks a server to run read_file:
It’s the same four fields:
jsonrpcandid: exactly the same.method: MCP uses its own fixed name,tools/call, meaning “run a tool”.params: MCP decides what goes inside: the tool’snameand itsarguments.
That’s the whole secret. MCP is JSON-RPC plus an agreed list of method names. The two you’ll use most:
| Method | Question it asks |
|---|---|
tools/list |
“What tools do you have?” Each tool comes back with a name, a description and an input schema. |
tools/call |
“Run this tool with these arguments.” |
Two ways to connect: stdio and Streamable HTTP
The messages are the same JSON-RPC either way. Only the delivery changes.
| stdio | Streamable HTTP | |
|---|---|---|
| Where the server runs | On the same computer | Anywhere: another machine, the cloud, even localhost |
| How they talk | The host starts the server as a program and writes to its stdin, reads its stdout | Each message is an HTTP request; the server can stream answers back |
| Sign-in | None needed | Can ask for sign-in (OAuth) |
| Sharing | One user | Many users can share one server |
| Good for | Files on your disk, local tools | GitHub’s hosted server, a team database |
A rule of thumb: if the tool needs your machine, use stdio. If many people share it, use HTTP. One warning for stdio servers: never print to stdout, because stdout is the wire. Logs go to stderr.
One full trip: how an agent uses an MCP tool
Let’s put it all together with a real job: our agent must read Trends.txt and write articles from it. Three players: the LLM, our Java agent (the host, with its MCP client), and files-server.
- Connect. The host starts files-server over stdio and they agree on the protocol version.
tools/list. The client asks what tools the server has.- Three tools come back, each with a name, a description and an input schema.
- Task + tools go to the LLM, in the normal “tools” field. The LLM doesn’t know they came from MCP.
- The LLM asks for a tool:
read_filewith pathTrends.txt. tools/call. Instead of running a Java method itself, the host’s MCP client sends the call to the server.- The server runs it (plain
Files.readString) and returns the text. - The result goes into the chat history as a tool message, and the loop continues.
Steps 4, 5 and 8 are exactly what an agent did before MCP. The loop didn’t change. Only where the tool runs did.
Three ways to build with MCP
| Level | What | You write | Good for |
|---|---|---|---|
| 1. By hand | Read JSON from the pipe, route method names, build every MCP message shape | Everything, including versions, errors and transports | Learning how it works |
| 2. Official MCP SDK | Python, TypeScript, Java and more | Just your tools | Most projects |
| 3. Spring AI | Starters, auto-configuration, a tool is an annotated method | Just your tools | Spring Boot apps |
Two small corrections to how this is often said. Level 1 is more than “just JSON-RPC”: you must also follow every MCP rule on top. And Spring AI isn’t a separate implementation: it uses the official Java SDK underneath. The Spring team helps maintain that SDK.
The MCP Java SDK (io.modelcontextprotocol.sdk:mcp, Java 17+) gives you both sides, server and client, sync or async, over stdio or Streamable HTTP. It ships two generations side by side, because MCP changed a lot in 2026:
| Modern | Legacy | |
|---|---|---|
| Spec version | 2026-07-28 | 2025-11-25 and earlier |
| Start-up | No handshake, no session; every request carries its version in _meta |
An initialize handshake, then a session |
| Java package | …modern |
the classic packages |
| Status | New; may still change before SDK 3.0 | Still widely used, not deprecated |
The rule: match the other side. A modern client can’t talk to a legacy server, or the other way round.
Cheat sheet
| Term | One line |
|---|---|
| MCP | One standard way for AI apps to use tools |
| Host | The AI app; runs the loop, talks to the LLM |
| MCP client | Connector inside the host; one per server |
| MCP server | Small program that wraps a real system and offers tools |
| RPC | Calling a function on another computer as if it were local |
| JSON-RPC 2.0 | RPC with JSON messages: jsonrpc, method, params, id |
| Notification | A message with no id; no reply |
tools/list / tools/call |
“What tools do you have?” / “Run this tool” |
| stdio / Streamable HTTP | Local pipe / web service; same messages |
What’s next
Ready to build one? In MCP Hello World in Java we write a small MCP server and client with the Java SDK over stdio, and see the only three spots you change for your own tools.
See it in action
Prefer watching? This video walks through the same ideas with live, hands-on demos.
Watch on YouTube ↗
Comments