What is MCP? Model Context Protocol explained, from RPC to your first tool call

MCP is one standard plug that lets any AI app use any tool. We start with the problem it solves, draw the host, client and server, then open the plug to see the RPC and JSON-RPC inside, and follow one tool call end to end.

Without MCP, three agents each contain their own file code, GitHub code and database code, nine pieces of code in total. With MCP, each agent has a single MCP client, all clients talk through one standard MCP band, and three MCP servers for Files, GitHub and Database are each built once.
Fig. 1 — Without MCP, every agent rebuilds every tool. With MCP, each tool is built once and every agent plugs in.

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:

  1. Why MCP exists (the problem).
  2. What it looks like (host, client, server).
  3. How it talks underneath (RPC, then JSON-RPC).
  4. 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.

The LLM talks only to the host. The host, our Java agent or Claude Desktop or VS Code, runs the agent loop and holds MCP client 1 and MCP client 2. Client 1 talks to files-server over stdio; files-server offers read_file, list_files and save_file and wraps your disk. Client 2 talks to github-server over HTTP; it offers list_issues and create_issue and wraps GitHub's web API.
One client per server. The LLM sits outside MCP completely.
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 computer runs int r = subtract(42, 23). The call is packed as subtract, 42, 23 and sent over the network to another computer, where subtract runs. The result, 19, is sent back. Four steps: pack the call, send it, run it there, send the answer back.
Remote, but it feels local.

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 sends requests with ids 1, 2 and 3 in order. The server finishes id 3 first, then 1, then 2. Each answer carries its id, so 19 lands in slot 1, 7 in slot 2 and the hello list in slot 3. A message update with no id is a notification, and the server sends no reply.
Answers can come back in any order. The id puts each one in the right place.

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:

Left, a plain JSON-RPC request: jsonrpc 2.0, id 1, method subtract, params 42 and 23. Right, an MCP request: jsonrpc 2.0, id 7, method tools/call, params with name read_file and arguments path Trends.txt. jsonrpc and id are marked same; method is MCP's name for run a tool; params hold which tool and its inputs.
Same four fields. MCP only decides the method names and what goes inside params.

It’s the same four fields:

  • jsonrpc and id: exactly the same.
  • method: MCP uses its own fixed name, tools/call, meaning “run a tool”.
  • params: MCP decides what goes inside: the tool’s name and its arguments.

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.

A sequence of eight steps between the LLM, our Java agent and files-server. 1: start the server and agree on the version. 2: tools/list. 3: the server returns read_file, list_files and save_file. 4: the agent sends the task and the tools to the LLM. 5: the LLM replies with a tool call, read_file Trends.txt. 6: the agent sends tools/call to the server. 7: the server runs Files.readString and returns the text. 8: the result goes into the history and the loop runs again.
Red messages are MCP. Black messages are the same LLM chat you'd have without MCP.
  1. Connect. The host starts files-server over stdio and they agree on the protocol version.
  2. tools/list. The client asks what tools the server has.
  3. Three tools come back, each with a name, a description and an input schema.
  4. Task + tools go to the LLM, in the normal “tools” field. The LLM doesn’t know they came from MCP.
  5. The LLM asks for a tool: read_file with path Trends.txt.
  6. tools/call. Instead of running a Java method itself, the host’s MCP client sends the call to the server.
  7. The server runs it (plain Files.readString) and returns the text.
  8. 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.

Video thumbnail: What is MCP? Model Context Protocol explained, from RPC to your first tool callWatch on YouTube ↗

Comments

LEAVE A COMMENT
No sign-up. Comments appear after a quick review.