Availit World How AI really works, in your language

Lesson 35 of 4633 minFacts checked October 21, 2026

MCP: one plug for every tool

In the tool-calling lesson you wrote tools inside your own program. But an agent may need your files, your calendar, a database and dozens of online services, and every app would have to connect each one by hand. The Model Context Protocol is a shared plug: write a tool server once, and every app that speaks MCP can use it.

In this lesson you will

  • Explain the problem MCP solves, and the jobs of the host, the client and the server
  • Read the JSON-RPC messages that list and call tools in the current version, 2026-07-28
  • Tell tools, resources and prompts apart, and the two kinds of error
  • Write a small MCP server in Python, test it, and connect it to a coding agent
  • Keep tool definitions from filling the context, with tool search and code
  • Judge a server before you trust it with your computer or your accounts
On this page
  1. Many apps, many tools
  2. Hosts, clients and servers
  3. The messages, step by step
  4. Tools, resources and prompts
  5. Write your own server
  6. Too many tools
  7. Trust, but check
  8. Remember
  9. Check yourself

Many apps, many tools

Before MCP, every AI application connected every service in its own way. A chat app wrote its own code for Google Drive, a coding tool wrote different code for the same Drive, and a third app did it again. With many apps and many services, the work multiplies:

Why a shared protocol saves work
without a standard: N × M connectors

Each of N apps needs its own connector for each of M services.

with a standard: N + M

Each app learns the protocol once, and each service offers one server.

10 apps, 100 services: 1,000 against 110

And a new service works at once in all ten apps.

Anthropic released the Model Context Protocol, MCP, as an open standard in November 2024. Its designers took the idea from the Language Server Protocol, which lets any code editor support any programming language through one shared protocol. During 2025 OpenAI, Google and Microsoft added MCP support to their own products, and in December 2025 Anthropic handed it to the new Agentic AI Foundation at the Linux Foundation, so no single company owns it.

The ecosystem grew fast. A study published in October 2025 collected 67,057 MCP servers from six public registries. In China, Alibaba’s ModelScope opened an MCP marketplace on 15 April 2025 with nearly 1,500 servers for search, maps, file systems and developer tools, among them Alipay’s server for creating and checking payments and MiniMax’s tools for speech, images and video.

Quick check

A team builds an MCP server for its school’s timetable. Which apps can use it?

Show the answer

Answer: Any application that supports MCP, without new code for each one That is the point of a standard: one server, every client. MCP is now run by a Linux Foundation project and supported by many companies’ apps.

Hosts, clients and servers

The three roles
What it isExamples
HostThe AI application you use. It holds the model, decides what the model sees and asks you before tools run.Claude Code, Codex CLI, Qwen Code, Cursor, a chat app
ClientA connector inside the host. Each client talks to one server.The host’s connection to the notes server
ServerA program that offers tools and data through MCPA file server, a GitHub server, a database server
Where a tool call travels
  1. Modelasks for a tool call
  2. Hostchecks permissions, may ask you
  3. MCP clientsends tools/call
  4. MCP serverruns the tool
  5. The servicefiles, database, web API

Notice what the model does not do: it never talks to an MCP server. The host turns the server’s tools into ordinary tool definitions, exactly like the ones in the tool-calling lesson. When the model asks for a call, the host’s client sends it to the server and hands the result back. MCP is the link between the host and its servers; the model sees only tools.

Servers are reached in one of two ways, called transports:

  • stdio. The host starts the server on your own computer as a child program, and they exchange one JSON message per line through its standard input and output. The server writes its logs to standard error, never to standard output. Credentials come from environment variables.
  • Streamable HTTP. The server runs somewhere else, often a company’s service. The client sends each message as an HTTP POST to one address, and the answer comes back either as JSON or as a stream. Signing in uses OAuth: you approve access in your browser, and the client gets a token that is valid for that server alone.

Quick check

Your coding agent uses an MCP server for your project’s database. Who actually sends the tools/call message to that server?

Show the answer

Answer: The MCP client inside the host The model only asks for a tool call. The host decides whether to allow it, and its client sends the request to the server.

The messages, step by step

MCP messages follow JSON-RPC 2.0, a small standard for calling functions with JSON. A request has an id and a method; the response carries the same id and either a result or an error; a notification has no id and gets no reply.

Below is a real exchange with the small notes server you will write later in this lesson, recorded with the official Python SDK, version 2.3.0. The messages are only shortened. Since version 2026-07-28 MCP is stateless: every request carries its protocol version and the client’s capabilities in a _meta field, so the server needs to remember nothing between requests. After the first request, _meta is shortened here to { ... }.

A host adds a note through an MCP server
  1. MCP client, in the host

    The host starts the server as a child program, python notes_server.py, and asks what it offers.

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "server/discover",
      "params": {
        "_meta": {
          "io.modelcontextprotocol/protocolVersion": "2026-07-28",
          "io.modelcontextprotocol/clientInfo": { "name": "lesson-client", "version": "1.0" },
          "io.modelcontextprotocol/clientCapabilities": {}
        }
      }
    }
  2. MCP server

    The server names the protocol versions it supports and what it can do.

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": {
        "resultType": "complete",
        "supportedVersions": ["2026-07-28"],
        "capabilities": { "tools": { "listChanged": true }, ... },
        "_meta": { "io.modelcontextprotocol/serverInfo": { "name": "notes" } }
      }
    }
  3. MCP client, in the host

    Next, the list of tools.

    {
      "jsonrpc": "2.0",
      "id": 2,
      "method": "tools/list",
      "params": { "_meta": { ... } }
    }
  4. MCP server

    Two tools, each with a name, a description and a JSON Schema for its arguments. (The real reply also gives an output schema for each tool.)

    {
      "jsonrpc": "2.0",
      "id": 2,
      "result": {
        "resultType": "complete",
        "tools": [
          {
            "name": "add_note",
            "description": "Save a short note. Returns the note's number.",
            "inputSchema": {
              "type": "object",
              "properties": { "text": { "type": "string" } },
              "required": ["text"]
            }
          },
          {
            "name": "search_notes",
            "description": "Return every saved note that contains the query (not case-sensitive).",
            "inputSchema": {
              "type": "object",
              "properties": { "query": { "type": "string" } },
              "required": ["query"]
            }
          }
        ]
      }
    }
  5. You

    Please remember: exam on 3 November, chapters 4 to 6.

  6. Model

    The host gave the model both tools as ordinary tool definitions. The model asks for one:

    add_note(text="Exam on 3 November: chapters 4 to 6")
  7. MCP client, in the host

    The host allows the call, and its client sends it to the server.

    {
      "jsonrpc": "2.0",
      "id": 3,
      "method": "tools/call",
      "params": {
        "name": "add_note",
        "arguments": { "text": "Exam on 3 November: chapters 4 to 6" },
        "_meta": { ... }
      }
    }
  8. MCP server

    The result: text for the model, the same value as structured data, and isError: false.

    {
      "jsonrpc": "2.0",
      "id": 3,
      "result": {
        "resultType": "complete",
        "content": [{ "type": "text", "text": "Saved as note 1." }],
        "structuredContent": { "result": "Saved as note 1." },
        "isError": false
      }
    }
  9. Model

    Saved. It is note 1 in your notes.

Versions up to 2025-11-25 worked differently: the client first sent an initialize request, the two sides agreed on a version and capabilities once, and the connection was then a session with its own state. You will still see that handshake in many servers and older tutorials. The official SDKs speak both versions; the server above also answered an old-style initialize correctly.

Things go wrong in two different ways, and MCP keeps them apart:

The two kinds of error, from the same serverjson
// A tool execution error: search_notes was called without its query
{
  "jsonrpc": "2.0",
  "id": 5,
  "result": {
    "resultType": "complete",
    "content": [{ "type": "text", "text": "Error executing tool search_notes: 1 validation error ... query Field required" }],
    "isError": true
  }
}

// A protocol error: a request sent without the required _meta fields
{
  "jsonrpc": "2.0",
  "id": 7,
  "error": {
    "code": -32602,
    "message": "params._meta must be an object carrying the required 'io.modelcontextprotocol/protocolVersion' and 'io.modelcontextprotocol/clientCapabilities' envelope keys"
  }
}
  • A tool execution error is a normal result with isError: true. Its text goes back to the model, which can read what went wrong and try again with the right arguments, as in the agent-loop lesson.
  • A protocol error is a JSON-RPC error: the request itself was malformed. It is a bug in the host or the server, and the model can rarely fix it. Code -32602 means invalid parameters.
  • The // lines are notes for you; real JSON has no comments.

Quick check

A tool call fails because the model gave a date in the wrong format. How should the server report it?

Show the answer

Answer: As a result with isError: true and a clear message, so the model can correct itself The specification says tool execution errors belong in the result, where the model can see them and retry. Protocol errors are for malformed requests.

Tools, resources and prompts

A server can offer three kinds of thing. They differ in who decides to use them:

What a server offers
Who decides to use itExample
ToolsThe model, during its worksearch_notes, create_issue, run_query
ResourcesThe application or the user, who choose data to add to the contextA file, a database’s table layout, today’s timetable, each with an address such as file:///…
PromptsThe user, often as a slash commandA ready-made “summarise this week’s notes” template

Tools are by far the most used. A tool’s result can be text, an image, audio, structured JSON, or a link to a resource: an address the host can open later instead of a large file pasted into the context, the restorable compression of the context-engineering lesson.

Sometimes a server needs something from the user in the middle of a call, such as a choice or a missing detail. With elicitation the server asks the host to show the user a small form. In version 2026-07-28 this works without any state on the server: it answers input_required with its questions, and the client sends the original request again together with the answers.

Because the protocol keeps no sessions, a server that needs state across calls, such as a shopping basket or an open browser page, returns a handle: an ID that the model passes back as an ordinary argument in later calls. Longer jobs can use the official tasks extension, which returns a handle at once and lets the client ask for progress. Another extension, MCP Apps, lets a server show interactive charts or forms inside the conversation.

Quick check

You want users to pick which project document goes into the conversation, without the model deciding. Which MCP feature fits?

Show the answer

Answer: A resource Resources are data that the application or the user chooses to add. Tools are for the model to call on its own.

Write your own server

The official Python SDK turns ordinary functions into MCP tools. Install it with pip install "mcp[cli]" (Python 3.10 or newer), save this as notes_server.py, and you have a working server:

notes_server.py: a server with two toolspython
import json
from pathlib import Path
from mcp.server import MCPServer

NOTES = Path(__file__).with_name("notes.json")
mcp = MCPServer("notes")

def load():
    return json.loads(NOTES.read_text(encoding="utf-8")) if NOTES.exists() else []

@mcp.tool()
def add_note(text: str) -> str:
    """Save a short note. Returns the note's number."""
    notes = load()
    notes.append(text)
    NOTES.write_text(json.dumps(notes, ensure_ascii=False), encoding="utf-8")
    return f"Saved as note {len(notes)}."

@mcp.tool()
def search_notes(query: str) -> list[str]:
    """Return every saved note that contains the query (not case-sensitive)."""
    return [n for n in load() if query.lower() in n.lower()]

if __name__ == "__main__":
    mcp.run()  # stdio: one JSON message per line on standard input and output
  • The docstring becomes the tool’s description, and the type hints become its input schema, exactly as in the tools/list reply above. The return type becomes an output schema.
  • add_note changes a file, and search_notes only reads. A host may let read-only tools run freely and ask you before the other.
  • Errors need no extra code: the SDK turns a wrong or missing argument into a result with isError: true.

Test it without any model, with a few lines of client code. The client starts the server, lists its tools and calls them, just as a host would:

client.py: talking to the server directlypython
import asyncio
from mcp import Client, StdioServerParameters

server = StdioServerParameters(command="python", args=["notes_server.py"])

async def main():
    async with Client(server) as client:
        listed = await client.list_tools()
        for tool in listed.tools:
            print(tool.name, "-", tool.description)
        result = await client.call_tool("add_note", {"text": "Bring the science notebook on Monday"})
        print(result.content[0].text)
        result = await client.call_tool("search_notes", {"query": "science"})
        print(result.structured_content)

asyncio.run(main())
  • Run it in the same folder as the server. It prints both tools, then Saved as note 1., then {'result': ['Bring the science notebook on Monday']}.
  • This is how you check a server before you trust a model with it: you see exactly what each tool returns.

To give it to a coding agent, register it. In Claude Code, the command is claude mcp add --transport stdio notes -- python notes_server.py. Or put a .mcp.json file in your project, so everyone who works on it gets the same server:

.mcp.jsonjson
{
  "mcpServers": {
    "notes": {
      "command": "python",
      "args": ["notes_server.py"]
    }
  }
}
  • Claude Code asks for approval before it uses servers from a project’s .mcp.json, because the file could come from anyone who can change the project.
  • Other harnesses, such as Codex CLI and Qwen Code, keep a similar list in their own settings files; their documentation gives the exact format.

Quick check

Where does the description that the model reads for add_note come from?

Show the answer

Answer: The function’s docstring, sent by the server in its tools/list reply The SDK turns the docstring into the description field. Write it as carefully as the tool-calling lesson taught: it is the only manual the model gets.

Too many tools

Every tool from every connected server is a tool definition, and tool definitions sit at the start of the context on every request (the context-engineering lesson). Connect a few large servers and they fill a good part of the window before you have typed a word.

Try itWhat connected servers cost

With all five servers connected, 58 tool definitions take about 55 thousand tokens: over a quarter of the window, on every request, and 58 tools for the model to choose from. Turn on tool search: the model starts with one search tool and loads only the definitions it finds. Now connect only Splunk with its two tools, and see why tool search is not worth it for a small server.

This interactive part needs JavaScript.

Two answers to this problem appeared in November 2025, both from Anthropic’s engineers:

  • Tool search. Tool definitions are marked to load later, and the model gets one tool that searches them. In Anthropic’s tests on MCP tasks, this also made tool choice more accurate, because the model faced a few likely tools instead of dozens: one Claude model went from 49 % to 74 % correct. Claude Code offers MCP tool search for the same reason.
  • Code instead of calls. The harness presents each server as a folder of small code files. The model reads only the files it needs, then writes a short program that calls the tools, filters the data and returns only the result. In Anthropic’s example of copying a document from one service into another, this cut the tokens from about 150,000 to about 2,000. The price: the model’s code must run in a safe sandbox (the harnesses lesson).

Researchers in China work on the same problem. MCP-Zero (2025) lets the model ask for the kind of tool it needs, which a router then finds among 2,797 tools from 308 servers; on one benchmark it cut the tokens spent on tool definitions by 98 %. LiveMCPBench (August 2025), from the Institute of Software at the Chinese Academy of Sciences, gave agents 70 real servers with 527 tools and 95 everyday tasks. The best model in its first version finished about 79 % of the tasks, and the authors found that finding the right tool among hundreds is a skill of its own.

Quick check

An agent has 4 tools from one small server. Should it use tool search?

Show the answer

Answer: Probably not: the search tool and the tools it finds cost about as much as loading all four Tool search pays off when there are many tools, about ten or more by Anthropic’s advice. For a handful, simply load them.

Trust, but check

An MCP server is a program you run, or a service you allow to act for you. The specification states the principles plainly: users must consent to and understand what data is shared and what actions are taken; hosts must ask before exposing user data to a server and before invoking any tool; and a tool’s description is untrusted unless it comes from a server you trust. MCP cannot enforce these rules itself. They are the job of the host, and of you.

Researchers have measured the risks:

  • Weak vetting. The October 2025 study of 67,057 servers found that public registries check little about who publishes a server or who owns it, so a fake or taken-over server can reach users. Its scanning tool flagged 833 servers with code weaknesses.
  • Descriptions steer the model. A tool’s description is text the model reads and tends to follow. MCPTox (August 2025) built test cases on 45 real servers with 353 tools and tried them on 20 AI agents: harmful descriptions often succeeded, more capable models were often more easily misled because they follow instructions so well, and agents refused less than 3 % of the time.
  • Local servers run as you. A stdio server is a program with the same permissions as your user account. The specification asks hosts to show the exact command before they run a new server, and to sandbox servers where possible.
  • Tokens must stay put. A remote server must accept only tokens issued for it, and must never pass your token on to another service. The specification forbids this “token passthrough”.
  1. Prefer servers published by the service itself, or open-source servers you can read.
  2. Read the tool list and the descriptions before you connect a server, with a client like the one above or your host’s server view.
  3. Grant the smallest access that works: read-only where possible, one folder instead of your whole disk, the narrowest sign-in permission.
  4. Keep approval switched on for tools that write, delete, pay or send.
  5. Never connect a server that reads untrusted content, such as web pages or email, in the same agent as tools that can send your data out, unless a person approves each sending step: the lethal trifecta of the tool-calling lesson.
  6. Remember that a server’s tool list can change while you use it; the protocol even has a notification for that. What you approved last month is not automatically what runs today.

Is each habit safe, or risky?

0 of 8 sorted
  • Reading a server’s tools and descriptions before connecting it

    Answer: Safe habit

  • Installing a server from a registry because it has a popular-sounding name

    Answer: Risky habit

  • Giving a file server access to one project folder only

    Answer: Safe habit

  • Turning off approval for every tool so the agent works faster

    Answer: Risky habit

  • Choosing the read-only scope when a service asks what to allow

    Answer: Safe habit

  • Pasting your password into a server’s settings file and committing it to git

    Answer: Risky habit

  • Running a new local server inside a container first

    Answer: Safe habit

  • Letting an agent read your inbox and send email with no one checking

    Answer: Risky habit

Remember

  • MCP is an open standard that connects AI applications to tools and data: one server works in every host that speaks it.
  • The host holds the model and asks for consent; a client in the host talks to one server; the model sees only ordinary tools.
  • Messages are JSON-RPC 2.0. Since 2026-07-28 MCP is stateless: each request carries its version and capabilities in _meta.
  • Servers offer tools (chosen by the model), resources (chosen by the app or user) and prompts (chosen by the user).
  • Tool failures come back as results with isError: true, so the model can fix them; protocol errors mean a malformed request.
  • Tool definitions fill the context, so large tool sets need tool search or code that calls tools; good servers keep their output small.
  • A server is code that acts for you: check who made it, read its tools, grant the least access, and keep approval on for risky actions.

Words to know

MCP
The Model Context Protocol: an open standard for connecting AI applications to tools and data.
Host
The AI application that holds the model, connects to MCP servers and asks the user for consent.
MCP client
The connector inside a host that talks to one MCP server.
MCP server
A program that offers tools, resources and prompts through MCP.
JSON-RPC
A small standard for requests, responses and notifications written in JSON, used by MCP.
stdio transport
Running a server as a child program and exchanging one JSON message per line through its input and output.
Streamable HTTP
Reaching a remote MCP server by sending each message as an HTTP POST and reading the answer as JSON or a stream.
Resource
Data a server offers at an address, which the application or user can add to the context.
Elicitation
A server asking, through the host, for information from the user in the middle of a request.
Stateless protocol
A protocol in which every request carries everything needed to answer it, so the server keeps no session.
Tool search
Loading tool definitions only when a search finds them, instead of putting every definition into the context.
Tool poisoning
Hiding harmful instructions in a tool’s description, which the model may follow.
Token passthrough
A server forwarding a user’s access token to another service. MCP forbids it.

Go to the source

This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.

Check yourself

5 questions. Tap the answer you think is right.

0 of 5 answered

What problem does a shared protocol like MCP solve?

Show the answer

Answer: It replaces N × M separate connectors with N + M: each app and each service implements the protocol once With a standard, a new server works in every host, and a new host can use every server.

Does the model talk to an MCP server directly?

Show the answer

Answer: No: the host shows the model ordinary tools, and the host’s client sends the calls The model only asks for tool calls. The host decides, and its MCP client talks to the server.

What changed in MCP version 2026-07-28?

Show the answer

Answer: It became stateless: no initialize handshake, and every request carries its version and capabilities Servers now remember nothing between requests. State that must last travels as explicit handles.

Why can connecting many MCP servers make an agent worse?

Show the answer

Answer: All their tool definitions fill the context and give the model many similar tools to confuse In Anthropic’s example, 58 tools took about 55 thousand tokens. Tool search loads only what a task needs and made tool choice more accurate.

MCPTox found that more capable models were often more easily misled by harmful tool descriptions. Why?

Show the answer

Answer: They follow instructions better, including instructions hidden where they do not belong Strong instruction-following is what the attack uses. Defences must come from the host and the user: trusted servers, least access and approval for risky actions.

Lesson complete

Answer every question above to complete this lesson.

Your progress is saved on this device only.

Next lessonMulti-agent systems: when many models beat one
Previous lesson All lessons

Choose your language