Model Context Protocol (MCP) Part 2: How MCP Works, Explained with a Hospital
DEV Community

Model Context Protocol (MCP) Part 2: How MCP Works, Explained with a Hospital

Part 1 covered why MCP exists, what the name means, and what it gives you.

This part shows how it works: what a "tool" is, the three components of the architecture, the step-by-step flow of a request, why MCP became stateless, and who builds the servers.

The running example is still CampusBuddy, the AI assistant for college students. To make the moving parts easy to picture, this part uses a hospital as the everyday comparison.

Each topic ends with a "Remember for the test" box, and the article finishes with common confusions, a quick reference table, and practice questions with answers.

Part A: What a Tool Is in MCP

In MCP, the word tool has a specific meaning. A tool is an executable function that your LLM or AI application can invoke.

Take a GitHub MCP server. It can expose functions such as:

  • Create a repository
  • Delete a repository
  • Read an issue
  • Write an issue

Two properties define these tools:

  • They accept JSON input and return JSON output.
  • They are invocable functions: the LLM or application uses them to execute specific tasks.

Why Tools Are Useful: An Abstraction Layer

Tools give the LLM an abstraction layer. When the LLM needs to do something with an external system, it does not need to know the exact API endpoint. It only needs to know that these functions exist and that it can invoke them.

Think of a hospital's list of available tests: blood test, X-ray, ECG. A doctor orders "X-ray, left wrist." The doctor does not need to know which buttons to press on the X-ray machine. The test is a ready made function that takes clear inputs (which patient, which body part) and returns a clear output (the report).

Remember for the test (Part A)

  • A tool is an executable function the LLM or application can invoke.
  • Tools take JSON input and return JSON output.
  • Example: a GitHub MCP server can expose create repository, delete repository, read issue, and write issue.
  • Tools are an abstraction layer. The LLM does not need to know the API endpoint.

Part B: The Three Core Components

MCP architecture has three components: the host, the MCP client, and the MCP server.

The Hospital Map

Here is how the pieces line up before looking at each one:

Hospital MCP world CampusBuddy example
Patient End user A student asking a question
Hospital (runs the whole operation) Host The CampusBuddy app backend
Doctor (decides which tests are needed, explains the result in plain words) LLM GPT, Gemini, Claude, or another model
Runner carrying standard request forms to the lab MCP client The connector code inside CampusBuddy
Lab technician (operates the machines, holds the lab keys) MCP server The MySQL server, payment server, or Slack server
Lab machine (X-ray, blood analyzer) External tool The timetable database, Razorpay, Slack
Test catalogue (what the lab offers and what each test needs) Tool list with input schemas "Get timetable: needs student ID and date"

1. Host

The host is an LLM powered application. It is the AI application that contains the AI features and uses an LLM, and it is the application the end user actually interacts with.

In CampusBuddy, the backend of the app, which handles the overall application logic and performs the operations, is the host.

A host can be written in any language or framework, for example Node.js or Django. Tools such as Claude Code and Codex can also act as hosts in the MCP architecture.

2. MCP Client

In most MCP architectures, the MCP client lives inside the host application. Its job is to send requests to the MCP server and to coordinate and orchestrate the work between the LLM and the MCP server.

Like the runner, it carries requests in a standard format and brings the results back.

Technically, an MCP client is a component that maintains a connection with an MCP server. That lets it retrieve relevant context from the server and hand it to the host application or LLM for use.

3. MCP Server

The MCP server is best thought of as a translator. Suppose the LLM needs a tool such as MySQL. You install or configure an appropriate MCP server for MySQL.

When a student asks "What classes do I have tomorrow?", the LLM decides it needs the timetable database. The request travels to the MCP server, whose job is to execute the required command and fetch the data from the external tool, just as the lab technician runs the test on the machine.

The server returns that data to the MCP client. The client passes it back to the LLM through the host. The LLM then turns the raw result into a human friendly response the student can easily read, the way a doctor explains a lab report in plain words.

Technically, an MCP server is a program whose job is to serve context and data to the host application.

Component What it is Where it lives Main job
Host LLM powered application the user interacts with Your application backend (Node.js, Django, Claude Code, Codex) Handles application logic and coordinates everything
MCP client A connection manager Usually inside the host Sends requests to the server, retrieves context, orchestrates between LLM and server
MCP server A translator program One per tool (for example, MySQL) Executes commands on the external tool and returns data and context

Remember for the test (Part B)

  • Three components: Host, MCP client, MCP server.
  • Host: the LLM powered application the end user interacts with. Written in any language or framework. Claude Code and Codex can act as hosts.
  • MCP client: usually lives inside the host, sends requests to the server, maintains the connection, retrieves context, and orchestrates between the LLM and the server.
  • MCP server: a translator that executes commands on the external tool and serves context and data to the host.

Part C: The Complete Flow of a CampusBuddy Request

Now put all the pieces together. A student uses CampusBuddy, and everything is built with MCP.

Step 1: Tool Discovery

This is like the runner collecting the test catalogue when the hospital opens for the day.

When CampusBuddy starts, the MCP client asks the MCP server: "What tools are available?" The server responds with the list of tools and, importantly, the input schema for each tool, meaning what information each tool needs. The host stores this list.

As a result, the LLM knows every available tool and what it can do, without anything being hardcoded.

Step 2: User Query

The student asks: "What classes do I have tomorrow?" The host forwards the query to the LLM.

Step 3: LLM Decision

The LLM, like the doctor, reads the question and decides which tool is needed: the timetable lookup.

A crucial point: the LLM does not execute anything itself. It only decides the intent, meaning what needs to be done. The doctor writes the test order, but does not operate the machine.

Step 4: Host Execution

The host application takes the LLM's decision and identifies the tool to invoke. The host instructs the MCP client, the client sends the request to the MCP server, and the server executes it against the timetable database and returns the response to the host. The host then gives the response to the LLM.

In the hospital, this is the runner carrying the order to the lab technician and bringing the report back.

Step 5: The LLM Generates a Response

The LLM processes the tool's result and writes a human friendly answer: "Tomorrow you have Data Structures at 9, then Networks at 11." This is displayed to the student.

Step 6: Follow Up Queries

The student may ask something else, for example "Pay my exam fee." The LLM already knows the available tools, so it can directly decide to use Razorpay. The same flow repeats: the host executes through the client and server, the result returns, and the LLM replies.

A tool like Slack can be used the same way for "Let my class group know I'll be late."

Tool discovery -> User query -> LLM decision -> Host execution -> LLM response -> Follow ups (client asks(host sends (intent only, (host tells (human friendly(same flow server forto LLM) no execution) client, clientanswer shown)repeats) tools + schemas)calls server)

A Note on Who Does What

An earlier simplified description says the LLM "sends the request" to the MCP client. The workflow clarifies the true division of labor:

  • The LLM decides (intent).
  • The host executes, using the MCP client to talk to the MCP server.
  • The MCP server talks to the external tool.

For test questions, remember that the LLM never runs the tool directly.

Remember for the test (Part C)

  • Six steps: tool discovery, user query, LLM decision, host execution, LLM response, follow up queries.
  • Discovery happens at startup. The client asks the server for tools, and the server returns the tool list plus each tool's input schema. The host stores it. Nothing is hardcoded.
  • The LLM only decides the intent. It does not execute anything.
  • The host executes: it instructs the MCP client, the client calls the MCP server, and the server runs the tool and returns the response.
  • Follow up queries repeat the same workflow with other tools such as Razorpay and Slack.

Part D: Stateful Versus Stateless MCP

When MCP was first introduced, it was a stateful protocol. That made it different from HTTP, which is stateless.

According to the video, MCP later became stateless in July 2026. Stateless means the MCP server can treat every incoming request independently instead of treating each one as part of the same session.

The Hospital Version

Stateful is like needing one particular lab technician because only that person remembers your earlier visit and what was said. If that technician is busy, you wait, and the hospital must keep sending you back to the same person. This is called session pinning.

Stateless is like a request form that carries everything needed (patient ID, which test). Any technician on duty can pick it up and complete it. Patients can be sent to whoever is free, in turn. This is round robin distribution.

Why Stateless Is Better

Easier scaling. It is simpler to scale AI applications that use MCP, especially horizontally (adding more server instances).

Round robin load balancing without session pinning. Because any server can handle any request, a load balancer can spread requests evenly, with no need to stick one client to one server.

Stateful (original) Stateless (July 2026)
Relationship to HTTP Different from stateless HTTP Matches HTTP's stateless nature
Requests Part of a session Each treated independently
Horizontal scaling Harder Easier
Load balancing Needs session pinning Round robin works

Beyond the transcript. I checked the July 2026 claim against current sources. It is accurate: the MCP specification version 2026-07-28 made the protocol core stateless, removing the initialization handshake and the session header so that any request can land on any server instance.

Removing protocol level sessions does not force your application to be stateless. If a server needs to carry state across calls, it can create an explicit handle and have the model pass it back.

The exam level takeaway from the transcript is unchanged: stateless means independent requests, easier horizontal scaling, and round robin load balancing without session pinning.

Remember for the test (Part D)

  • MCP started as a stateful protocol, unlike stateless HTTP.
  • MCP became stateless in July 2026 (specification version 2026-07-28).
  • Stateless: each request is treated independently.
  • Benefits: easier horizontal scaling, and round robin load balancing without session pinning.

Part E: Who Builds the MCP Server

As the developer, you build the host, and the MCP client sits inside it. So who builds the MCP server? There are three types, built by different parties.

1. Enterprise MCP Servers

Official servers built by the organizations themselves. For example, GitHub has built its own MCP servers.

In the hospital picture, this is the machine maker's own trained engineer running the machine: nobody knows it better. GitHub knows how its APIs work and what it wants to expose, and the responsibility for keeping the server updated belongs to GitHub too, so you get the most relevant, up to date information.

For production systems, try an official enterprise server first if one exists.

2. Open-Source MCP Servers

Community driven servers. A popular example is the MCP server built by Anthropic. They are a good starting point but may have limited features.

If no official enterprise server exists, an open source one is a good option.

3. Custom MCP Servers

Servers you build yourself, like a hospital's own in house lab.

Advantages:

  • Easier to secure to your requirements.
  • Easier to manage to your business needs.
  • You can implement your own custom business logic.
  • You can expose only the capabilities your organization needs.

Custom servers suit organizations and enterprises that need customized solutions.

Type Built by Strengths Limitations
Enterprise The tool's own organization (for example, GitHub) Official, kept up to date by the owner, best for production Only available for some tools
Open source The community (for example, Anthropic's server) Good starting point May have limited features
Custom You Secure, manageable, custom business logic, expose only what you need You build and maintain it

Individual Servers Versus Aggregators

You can use one MCP server per tool, or an MCP server aggregator: a single MCP server that connects to multiple tools. Popular aggregators include Pipedream, Make, and Zapier, which let you connect to thousands of tools.

The hospital version: instead of visiting a separate lab for every test, you go to one diagnostic centre that offers many tests at a single counter.

You can use the same idea when building your own: instead of one server per custom tool, build one aggregator that connects to several of your custom tools.

Remember for the test (Part E)

  • Three server types: enterprise (official, built by the organization, such as GitHub), open source (community, such as Anthropic's server), custom (built by you).
  • For production, try an official enterprise server first.
  • Open source servers are a good st
Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.