Skip to content
AgenticAIWiki
  1. Learn
  2. Part 7
  3. 35. MCP explained
  4. 35.2

Lesson 35.2 · 2 of 6 · 4 min read · Reviewed 24 Nov 2026

Hosts, clients and servers

By the end, you can

  • Name the roles of host, client and server in MCP.
  • Trace a tool call from model to server and back.

MCPModel Context Protocol (MCP): An open protocol that standardises how AI applications connect to tools, data and prompts through servers. has three roles.

Role What it is Example
Host The AI application the user works in Claude Code, Claude Desktop, your agent app
Client A connector inside the host, one per server The host’s link to the GitHub server
Server A program exposing tools, resources and prompts A GitHub server, a Postgres server

A call, end to end

  1. The host starts and its clients connect to each configured server.
  2. Each client asks its server what it offers (tools/list and similar), and the host gives those definitions to the model.
  3. The model asks for a tool, such as create_issue.
  4. The host routes the call to the right client, which sends a tools/call request to the server.
  5. The server does the work and returns a result (or isError: true).
  6. The host gives the result to the model as a tool result.

All messages are JSON-RPC 2.0: requests with an id, responses that match it, and notifications.

Key points

  • The host is the AI app (such as Claude Code); it runs one MCP client per connected server.
  • Servers expose capabilities; clients discover them and relay calls.
  • Messages are JSON-RPC 2.0 requests and responses.
Hands-on labRuns in the Playground

Trace a JSON-RPC tool call by hand

Follow one MCP tool call from discovery to result as JSON-RPC 2.0 messages between a host, a client and a server.

You will have: A script that prints each JSON-RPC request and response in order, with ids that match.

Steps

  1. Read the toy server: it handles tools/list and tools/call for one create_issue tool.
  2. Complete the Client so each request gets a fresh id and the reply is matched by id.
  3. Have the host list tools, then route a create_issue call to the right client.
  4. Print every message so you can see the request and response pairs.
  5. Call an unknown tool and check the server returns an error result instead of crashing.

Done when

  • The trace shows tools/list before tools/call.
  • Every response carries the same id as its request.
  • The unknown tool comes back with isError true.

Open in the Playground No API key needed.

Starter code (Python)
import json

class Server:
    """A toy MCP server with one tool."""
    def handle(self, msg):
        if msg["method"] == "tools/list":
            result = {"tools": [{"name": "create_issue", "description": "Open an issue",
                                 "inputSchema": {"type": "object", "properties": {"title": {"type": "string"}}}}]}
        elif msg["method"] == "tools/call":
            name = msg["params"]["name"]
            if name == "create_issue":
                result = {"content": [{"type": "text", "text": "Opened issue #101: " + msg["params"]["arguments"]["title"]}]}
            else:
                result = {"content": [{"type": "text", "text": "Unknown tool " + name}], "isError": True}
        return {"jsonrpc": "2.0", "id": msg["id"], "result": result}

class Client:
    def __init__(self, server):
        self.server, self.next_id = server, 1
    def request(self, method, params=None):
        # TODO: build {"jsonrpc": "2.0", "id": ..., "method": ..., "params": ...}, using a fresh id each time
        msg = {"jsonrpc": "2.0", "method": method, "params": params or {}}
        print("->", json.dumps(msg))
        reply = self.server.handle(msg) if "id" in msg else {"id": None, "result": {}}
        print("<-", json.dumps(reply))
        # TODO: check reply["id"] matches the request id
        return reply["result"]

client = Client(Server())
# TODO: list the tools, then call create_issue with a title, then call a tool that does not exist
print("tools found:", [])
Show a solution
import json

class Server:
    """A toy MCP server with one tool."""
    def handle(self, msg):
        if msg["method"] == "tools/list":
            result = {"tools": [{"name": "create_issue", "description": "Open an issue",
                                 "inputSchema": {"type": "object", "properties": {"title": {"type": "string"}}}}]}
        elif msg["method"] == "tools/call":
            name = msg["params"]["name"]
            if name == "create_issue":
                result = {"content": [{"type": "text", "text": "Opened issue #101: " + msg["params"]["arguments"]["title"]}]}
            else:
                result = {"content": [{"type": "text", "text": "Unknown tool " + name}], "isError": True}
        return {"jsonrpc": "2.0", "id": msg["id"], "result": result}

class Client:
    def __init__(self, server):
        self.server, self.next_id = server, 1
    def request(self, method, params=None):
        msg = {"jsonrpc": "2.0", "id": self.next_id, "method": method, "params": params or {}}
        self.next_id += 1
        print("->", json.dumps(msg))
        reply = self.server.handle(msg)
        print("<-", json.dumps(reply))
        assert reply["id"] == msg["id"], "response does not match request"
        print("   id matched:", msg["id"])
        return reply["result"]

client = Client(Server())
tools = [t["name"] for t in client.request("tools/list")["tools"]]
print("tools found:", tools)
ok = client.request("tools/call", {"name": "create_issue", "arguments": {"title": "Login button misaligned"}})
print("result:", ok["content"][0]["text"])
bad = client.request("tools/call", {"name": "delete_repo", "arguments": {}})
print("isError:", bad.get("isError", False))
Quick checkIn Claude Code connected to a GitHub MCP server, which part is the host?
How sure are you?
Pick an answer and how sure you are