MCP Explained: Host, Client, Server, Tools, Resources and Prompts
👋 In plain words: MCP (Model Context Protocol) is a standard plug for connecting AI applications to tools and data. Build an integration once as an MCP server, and every MCP-aware app, such as Claude Code, Claude Desktop or your own agent, can use it. This lesson explains the parts and the messages they exchange, one step at a time.
Before MCP, every AI app needed its own custom connector to every system, which meant many apps times many systems in integrations. MCP turns that into one server per system and one client per app. In this lesson you will learn the three roles (host, client, server), the three primitives (tools, resources, prompts), how messages flow over JSON-RPC, the two standard transports, and what changed in the 2026-07-28 protocol revision, with a runnable server you can explore.
🔑 Key terms
- Host: the AI application the user works in, such as Claude Code, Claude Desktop or your own agent.
- Client: the component inside the host that keeps one connection to one MCP server.
- Server: a program that exposes capabilities (tools, resources, prompts) over MCP.
- JSON-RPC 2.0: a simple message format of requests (
method,params,id), responses and notifications. - Transport: how the messages travel: stdio (a local subprocess) or Streamable HTTP (over the network).
💡 Think of it like this
MCP is USB for AI apps. Before USB, every printer needed its own cable and driver for every computer. With USB, a device works with any computer that has a port. An MCP server is the device, the host is the computer, and the client is the port.
🪜 Step 1: Learn the three roles
- The host (for example Claude Code) runs the model and decides when to use external capabilities.
- Inside the host, one client per server manages a connection: it discovers what the server offers and sends requests.
- Each server wraps one system, such as a test-results database, Jira or a file share, and answers the client’s requests.
One host can connect to many servers at once. One server can serve many hosts. That is the “build once, use everywhere” benefit, and the reason MCP was introduced.
🪜 Step 2: Know the three primitives
| Primitive | Controlled by | What it is | QA example |
|---|---|---|---|
| Tools | The model | Functions Claude can call to act or fetch data | get_failed_tests(build), create_bug(summary) |
| Resources | The application | Read-only data identified by a URI, which the host can attach as context | ci://builds/812/summary, a test plan file |
| Prompts | The user | Reusable prompt templates the user picks, often shown as slash commands | /triage build=812 |
The “controlled by” column is the key to exam questions: Claude decides to call tools; the app or user chooses which resources to include; the user invokes prompts.
🪜 Step 3: Explore a server with all three
This server exposes one tool, one resource template and one prompt. The client connects in-process, which is handy for tests and exploration:
📄 qa_server.py
from mcp.server.mcpserver import MCPServer
mcp = MCPServer("qa-results", instructions="Read CI test results.")
RUNS = {"812": {"passed": 482, "failed": ["test_checkout_total"]}}
@mcp.tool()
def get_failed_tests(build: str) -> list[str]:
"""List the failed tests of a CI build. build is the numeric build number, e.g. 812."""
return RUNS[build]["failed"]
@mcp.resource("ci://builds/{build}/summary")
def build_summary(build: str) -> str:
"""One-line summary of a CI build."""
r = RUNS[build]
return f"build {build}: {r['passed']} passed, {len(r['failed'])} failed"
@mcp.prompt()
def triage(build: str) -> str:
"""Triage the failures of a build."""
return f"Triage the failures of build {build}. Group them by likely root cause."
if __name__ == "__main__":
mcp.run() # stdio by default
📄 explore.py
import asyncio
from mcp import Client
from qa_server import mcp
async def main():
async with Client(mcp) as client:
tools = (await client.list_tools()).tools
templates = (await client.list_resource_templates()).resource_templates
prompts = (await client.list_prompts()).prompts
print("tools :", [(t.name, list(t.input_schema["properties"])) for t in tools])
print("resources:", [t.uri_template for t in templates])
print("prompts :", [p.name for p in prompts])
print("call tool ->", (await client.call_tool("get_failed_tests", {"build": "812"})).structured_content)
print("read resource ->", (await client.read_resource("ci://builds/812/summary")).contents[0].text)
print("get prompt ->", (await client.get_prompt("triage", {"build": "812"})).messages[0].content.text)
asyncio.run(main())⌨️ Terminal
python explore.py🖥️ Output
tools : [('get_failed_tests', ['build'])]
resources: ['ci://builds/{build}/summary']
prompts : ['triage']
call tool -> {'result': ['test_checkout_total']}
read resource -> build 812: 482 passed, 1 failed
get prompt -> Triage the failures of build 812. Group them by likely root cause.
- The tool’s type hints became its input schema and its docstring became the description Claude will read.
- The resource uses a URI template (
{build}), so one function serves every build.
🪜 Step 4: See the messages on the wire
MCP messages are JSON-RPC 2.0. A tool call looks like this request and response (shape only; IDs and extra metadata vary):
{"jsonrpc": "2.0", "id": 7, "method": "tools/call",
"params": {"name": "get_failed_tests", "arguments": {"build": "812"}}}
{"jsonrpc": "2.0", "id": 7,
"result": {"content": [{"type": "text", "text": "[\"test_checkout_total\"]"}],
"structuredContent": {"result": ["test_checkout_total"]}, "isError": false}}
The main methods are tools/list and tools/call, resources/list and resources/read, and prompts/list and prompts/get. Servers can also send notifications, for example that their tool list changed.
isError: true, so the model can read the problem and recover. Protocol-level problems (unknown method, malformed request) use JSON-RPC errors instead. Lesson 30 shows the difference.🪜 Step 5: Understand transports and connection setup
| Transport | How it works | Use it for |
|---|---|---|
| stdio | The host starts the server as a subprocess and exchanges messages over stdin/stdout | Local tools, one user, no network |
| Streamable HTTP | The server listens on an HTTP endpoint; clients POST messages and can receive streamed responses | Remote and shared servers, many users, authentication |
Connection setup changed in protocol revision 2026-07-28. Up to revision 2025-11-25, a session started with an initialize request in which client and server agreed a protocol version and capabilities. From 2026-07-28, that handshake is replaced by a server/discover request plus metadata on each request. The Python SDK (mcp 2.x) handles both, so your server code does not change; it matters when you read logs or debug an older client.
print() corrupts them. Log to stderr or a file instead.🪜 Step 6: Know where MCP fits with Claude
- Claude Code and Claude Desktop are MCP hosts: add a server and its tools appear (Lesson 29).
- The Claude Agent SDK can connect to MCP servers and even run in-process SDK MCP servers (Lesson 33).
- On the Messages API, either convert MCP tools with the SDK helpers and run them in your loop, or use the MCP connector (beta) to let Claude call a remote server directly (Lesson 29).
🌍 Real-world example: Ravi’s first MCP server
Ravi’s team had three copies of “fetch test results” code: in a Slack bot, a CLI script and a Claude Code helper. Each broke differently when the CI API changed. He replaced all three with one MCP server like qa_server.py. Now an API change means one fix, and every client gets it.
🧪 Practice Questions
Question 1. In MCP, which primitive is chosen and invoked by the model during a conversation?
- A. Tools
- B. Resources
- C. Prompts
- D. Transports
Show answer
Answer: A. Tools are model-controlled. Resources are attached by the application and prompts are chosen by the user.
Question 2. A team wants a read-only “current sprint test plan” that the user can attach to a conversation in Claude Desktop. Which primitive fits?
- A. A tool that returns the plan
- B. A resource identified by a URI
- C. A prompt template
- D. A notification
Show answer
Answer: B. Resources expose data for the application or user to include as context, identified by URI.
Question 3. Which two statements about MCP transports are true? (Choose 2.)
- A. stdio runs the server as a local subprocess communicating over stdin/stdout
- B. stdio is the right choice for a server shared by 200 users across the company
- C. Streamable HTTP suits remote, shared servers that need authentication
- D. Streamable HTTP cannot stream responses
Show answer
Answer: A and C. stdio is for local, single-user servers. Streamable HTTP serves remote clients and supports authentication and streaming.
Question 4. A stdio MCP server works in tests but fails in Claude Code with protocol parsing errors after a developer adds debug prints. What is the cause?
- A. The server needs a larger timeout
- B. print() writes to stdout, which carries the JSON-RPC messages, corrupting them
- C. Claude Code does not support Python servers
- D. The tool descriptions are too long
Show answer
Answer: B. In stdio transport, stdout is the protocol channel. Log to stderr instead.
📝 Assignment
- Task 1: Run
explore.py, then add a second toolget_flaky_tests(days: int)and a resourceci://builds/{build}/log.
✅ Done when: both appear in the listings and return data. - Task 2: For three systems your team uses, decide which should be tools, which resources and which prompts.
✅ Done when: each item has a primitive and a reason using the “controlled by” column. - Stretch: Write a pytest test that connects to
qa_server.mcpin-process and asserts the tool list, schema properties and the result ofget_failed_tests("812").
✅ Done when: the test passes without starting a subprocess.
❓ Frequently Asked Questions
🤔 What is MCP in simple terms?
An open standard that lets AI applications connect to tools and data through MCP servers, so one integration works with every MCP-compatible app.
🤔 What is the difference between an MCP host and an MCP client?
The host is the application (for example Claude Code). The client is the part of the host that maintains the connection to one MCP server.
🤔 What are MCP resources?
Read-only data, identified by URIs, that a server exposes for the application or user to include as context.
🤔 Does MCP use JSON-RPC?
Yes. MCP messages are JSON-RPC 2.0 requests, responses and notifications, sent over stdio or Streamable HTTP.
🏁 Summary
- Host = the AI app; client = one connection inside it; server = one wrapped system.
- Tools are model-controlled, resources are app-controlled, prompts are user-controlled.
- Messages are JSON-RPC 2.0:
tools/call,resources/read,prompts/getand more. - stdio for local servers, Streamable HTTP for remote and authenticated ones.
- Protocol 2026-07-28 replaced the
initializehandshake withserver/discover; the Python SDK handles both.
Next, continue with Build an MCP Server in Python Step by Step (stdio).
Independent study material by SQA Tools. Not affiliated with, endorsed by or sponsored by Anthropic. Claude is a trademark of Anthropic. Practice questions are original, not real exam content. Code outputs marked “sample run” come from running the exact code against a local stand-in for the Claude API, so real replies, IDs and token counts will differ. Exam facts checked against Anthropic’s official CCDV-F exam guide v1.1 on 24 Nov 2026.