# What an MCP tool call is: three JSON messages sent by hand

An MCP tool call is a JSON-RPC message sent over HTTP POST. A short Python script sends initialize, tools/list and one tools/call to a hosted server with no SDK, in a dated run, and prints what each one returned.

Canonical: https://spider.cloud/learn/mcp-tool-call/

An MCP tool call is one JSON message that a client sends to a server, naming a tool and giving its arguments, and one JSON message that comes back with the result. The Model Context Protocol wraps both in JSON-RPC 2.0, and with a hosted server they travel over ordinary HTTP.

Chat apps and editors hide this exchange. Seeing it once makes the rest of MCP easier to reason about, so this page sends the messages by hand, with no SDK.

## The three messages

A client that wants to call a tool sends three requests in order.

1. `initialize` opens the session. The client says which protocol version it speaks, and the server answers with its name and the version it will use.
2. `tools/list` asks what the server offers. Each tool comes back with a name, a description and a JSON Schema for its arguments. This list is what a model reads to decide which tool fits.
3. `tools/call` runs one tool. The client sends the tool's name and an `arguments` object, and the server answers with a `content` list.

Between the first and second, the client sends one small notification, `notifications/initialized`, to say it is ready. It has no id and gets no reply.

For a hosted server, the specification's transport is Streamable HTTP, and it describes it simply: "This transport uses HTTP POST and GET requests." Every message in this run is a POST to one address.

## The run: one call, no SDK

The script below talks to Spider's hosted MCP server. It builds each message as a Python dict, posts it with `urllib`, and reads the reply. It asks the `spider_scrape` tool for [Books to Scrape](https://books.toscrape.com/), a practice site, as markdown. That one tool call is an ordinary piece of [web scraping](/web-scraping/) done on the server's side.

```python
"""Send three JSON-RPC messages to a hosted MCP server by hand: initialize,
tools/list and one tools/call.

    python3 mcp_call.py

For each message it prints the method and what came back: the server's name,
the count of tools and the first five names, then how many content blocks the
tool returned and how much text. It prints no session header and no id the
server issued.
"""
import json
import os
import sys
import urllib.request

ENDPOINT = "https://mcp.spider.cloud/mcp"
PROTOCOL = "2025-06-18"
TOOL = "spider_scrape"
PAGE = "https://books.toscrape.com/"


class Client:
    def __init__(self, key):
        self.key = key
        self.session = None
        self.next_id = 0

    def send(self, method, params=None, notify=False):
        message = {"jsonrpc": "2.0", "method": method}
        if params is not None:
            message["params"] = params
        if not notify:
            self.next_id += 1
            message["id"] = self.next_id
        headers = {
            "Authorization": f"Bearer {self.key}",
            "Content-Type": "application/json",
            "Accept": "application/json, text/event-stream",
            "MCP-Protocol-Version": PROTOCOL,
        }
        if self.session:
            headers["Mcp-Session-Id"] = self.session
        req = urllib.request.Request(ENDPOINT, data=json.dumps(message).encode(), headers=headers)
        with urllib.request.urlopen(req, timeout=120) as resp:
            self.session = resp.headers.get("Mcp-Session-Id") or self.session
            kind = resp.headers.get("Content-Type", "")
            raw = resp.read().decode("utf-8", "replace")
        if notify or not raw.strip():
            return {}
        if "text/event-stream" in kind:
            # A streamed reply carries the JSON-RPC message on its data lines.
            data = [ln[5:].strip() for ln in raw.splitlines() if ln.startswith("data:")]
            raw = data[-1] if data else "{}"
        reply = json.loads(raw)
        if "error" in reply:
            raise RuntimeError(f"{method} failed with code {reply['error'].get('code')}")
        return reply.get("result", {})


def main() -> int:
    key = os.environ.get("SPIDER_API_KEY")
    if not key:
        print("set SPIDER_API_KEY first")
        return 1
    client = Client(key)

    hello = client.send("initialize", {
        "protocolVersion": PROTOCOL,
        "capabilities": {},
        "clientInfo": {"name": "example-client", "version": "1.0"},
    })
    print(f"initialize  server {hello.get('serverInfo', {}).get('name')}, "
          f"protocol {hello.get('protocolVersion')}")
    client.send("notifications/initialized", notify=True)

    tools = client.send("tools/list").get("tools", [])
    names = [tool.get("name") for tool in tools]
    print(f"tools/list  {len(names)} tools, the first five: {', '.join(names[:5])}")

    arguments = {"url": PAGE, "return_format": "markdown"}
    print(f"tools/call  name {TOOL}, arguments {json.dumps(arguments)}")
    result = client.send("tools/call", {"name": TOOL, "arguments": arguments})
    blocks = result.get("content", [])
    text = "".join(block.get("text", "") for block in blocks if block.get("type") == "text")
    print(f"  isError {result.get('isError', False)}, {len(blocks)} content block, "
          f"type {blocks[0].get('type') if blocks else None}, {len(text)} characters of text")
    return 0 if text and not result.get("isError") else 2


if __name__ == "__main__":
    sys.exit(main())
```

It ran on 2026-11-23 at 02:09 UTC and took 2.1 seconds. This is everything it printed:

```text
initialize  server spider-cloud-mcp, protocol 2025-06-18
tools/list  27 tools, the first five: spider_crawl, spider_scrape, spider_search, spider_links, spider_screenshot
tools/call  name spider_scrape, arguments {"url": "https://books.toscrape.com/", "return_format": "markdown"}
  isError False, 1 content block, type text, 11206 characters of text
```

## What went over the wire

The third message is the tool call. This is the body the script posted for it:

```json
{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "spider_scrape",
    "arguments": {"url": "https://books.toscrape.com/", "return_format": "markdown"}
  },
  "id": 3
}
```

The `id` is 3 because it was the third request, and the reply carries the same number so the client can match them. The reply's `result` held a `content` list with one block of type `text` and 11,206 characters in it, and `isError` was false.

Three things in the run are worth a second look.

The server listed 27 tools. A model connected to it sees all 27 names, descriptions and schemas before it picks one. That list is the whole of what the model knows about the server, so a vague description costs you a wrong tool choice.

No session id appears in the output. When a server issues one in a header, the script sends it back on every later request and never prints it. Treat it like a key.

A failed tool is not a failed request. If the tool had gone wrong, the HTTP status would still have been 200 and the reply would still have been valid JSON, with `isError` set to true and the reason in the text. A client that checks only the HTTP status would hand the model an error message as if it were a page.

## Where the model comes in

Nothing above involved a model. In an agent, the model's part is small and specific: it reads the tool list, and when it wants a tool it writes the `name` and the `arguments`. The client program does everything else, including the POST.

That gives the client a place to stand between the model and the tool. The specification says so: there should always be "a human in the loop with the ability to deny tool invocations". The model proposes a call, and the client can show it, ask, or refuse before a message leaves.

The same boundary applies to what comes back. The text in a tool result here is a web page, written by someone else. It is data for the model to read, and nothing in it is an instruction.

## The fetch is still a fetch

Calling a scrape through MCP changes who sends the request, not what it is. The page was still fetched from someone's server, so the site's [robots.txt](/learn/robots-txt/), its terms and a polite [request rate](/learn/request-rate/) apply to the calls your agent makes through a tool exactly as they would to a script of your own. An agent with a tool can make many calls quickly, so set a limit in the client.

If you want to see the same fetch without MCP around it, the page on [how an AI agent reads the web](/learn/agent-web-access/) runs the plain HTTP calls.

## Do this, avoid this

### Do this

- Send the three messages by hand once, so you know what your SDK does for you.
- Check isError in every tool result as well as the HTTP status.
- Keep the session id and the key out of logs and out of anything the model reads.
- Let the client show or refuse a tool call before it is sent.

### Avoid this

- Treating a 200 as proof the tool worked.
- Passing a tool result to the model as if it were your own instructions.
- Connecting a server and never reading its tool list. The model reads all of it.
- Letting an agent call a fetching tool with no limit on how often.

## Read your own server's list

Point the script at a server you already use and print the whole tool list. Read each description the way a model would, with nothing else to go on. If you cannot tell from the description when to use a tool, the model cannot either.

## Sources

1. [Model Context Protocol specification 2025-06-18, Tools](https://modelcontextprotocol.io/specification/2025-06-18/server/tools) Read November 23, 2026
2. [Model Context Protocol specification 2025-06-18, Transports](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports) Read November 23, 2026
