Skip to content
Index Ai Academy
Phase 1 · Tools & agents

Model Context Protocol

A standard way to plug tools and data into any AI app.

About 30 minutes · Prices and versions checked November 2026 · A free account opens the whole lesson.
Already have an account? Sign in to open this lesson

What it covers7

First principles

What problem does a common tool interface solve when several applications want the same capability?

MCP gives clients and servers a common way to discover and call capabilities. The host connects the model to those capabilities while preserving tool ownership and approval policy.

  1. Starting point

    Host connects a client to a reporting server

  2. What changes

    Client discovers the server's declared tool

  3. Result

    Host maps an approved model proposal into a tool call

Compare all three steps
  1. Starting point

    Host connects a client to a reporting server

  2. What changes

    Client discovers the server's declared tool

  3. Result

    Host maps an approved model proposal into a tool call

Complete and reverse the trace

Given Host connects a client to a reporting server and Host maps an approved model proposal into a tool call, write down the missing step that connects them.

Compare with the worked step

Client discovers the server's declared tool

Now take Client discovers the server's declared tool and the result above. Write an input and an implementation that could produce this trace.

Check one starting point

Host connects a client to a reporting server. Check that your implementation produces the result shown above.

Try it on a new case

A reports server publishes a read tool. Does discovery mean the model can execute that tool without the host?

Show worked reasoning

Discovery describes what exists. The host still mediates the action through its client and applies the application's permission rules.

Practice each learning objective
  1. Explain what problem MCP solves and the roles of host, client and server

    A learning assistant shows a report from a separate campaign service. Name the host, client and server in this interaction. Which component decides whether the assistant may use the report?

    Compare your reasoning

    The assistant application is the host. Its client holds the protocol connection. The campaign service is the MCP server exposing the report. The host sets its own permissions and the server still authorizes each operation on its side.

  2. Read and write MCP's JSON-RPC messages: initialize, tools/list and tools/call

    Write the method order for a client that starts a connection, discovers the report tool, and calls it with a campaign ID. Which field associates a reply with its request?

    Compare your reasoning

    Start with initialize, send the initialized notification after a successful response, then use tools/list and tools/call. Set a distinct id on each request. The response echoes that id. The initialized notification has no id and gets no response.

  3. Convert an MCP server's tools into Claude tool definitions

    A discovered tool is named get_report and takes a required string campaign_id. List the parts of its description and schema you would preserve when exposing the tool to a model.

    Compare your reasoning

    Preserve the tool name, description, and object input schema, including the campaign_id property type and required list. Keep the mapping from model-facing names to server names so a returned tool request can call the intended server.

  4. Judge whether an MCP server is safe to connect

    A server bundles read-only reports with the ability to publish a report. A learner only needs to read one campaign. Name two checks that stop this access from granting publishing rights.

    Compare your reasoning

    Scope the session to reading that campaign and permit only the read operation in the host. The server independently checks resource ownership and operation authorization. A tool description or a hidden button does not enforce a permission boundary.

Run, change, and build

Check this when debugging. Thinking MCP is a model or replaces tool use (it's a standard way to supply tools).

Trace the cause · Request and response
  1. Mark the supplied input, the expected response shape, and the rule that makes the result acceptable.
  2. Hold the scoring rule fixed and change one input. Inspect the returned fields before judging the complete response.
  3. Try the same reasoning on this case. A reports server publishes a read tool. Does discovery mean the model can execute that tool without the host?

Why it matters

Without a shared standard, every AI app needs its own custom connection to every tool. Your CRM for Claude. Your CRM again for a code editor. Again for a support bot. The Model Context Protocol (MCP) fixes this. It's an open standard, introduced by Anthropic in 2024 and now widely supported. A tool is written once, as an MCP server, and any app that speaks MCP can use it. When a vendor says "we have an MCP server", this lesson is what that means.

What you'll be able to do

  • Explain what problem MCP solves and the roles of host, client and server
  • Read and write MCP's JSON-RPC messages: initialize, tools/list and tools/call
  • Convert an MCP server's tools into Claude tool definitions
  • Judge whether an MCP server is safe to connect
Quick check
A company wants its CRM to work with several AI apps. What does MCP make possible?
  1. Writing the connector once, as a server any MCP host can use
  2. Training each AI app on the CRM's data directly
  3. Skipping the model, so the CRM answers questions itself
  4. Moving all the CRM's data into the AI app's database
Show the answer

Writing the connector once, as a server any MCP host can use

MCP is a shared standard, like USB for AI tools: a tool written once as an MCP server works in any app that speaks MCP, instead of one custom integration per app.

The idea: one plug for tools

This lesson rests on Tool use: the model asks for a tool, your code runs it. MCP changes where the tool comes from, not how it is called.

Think of USB. Before it, every printer and keyboard needed its own special port. With USB, one plug fits any computer. MCP is that plug for AI tools.

There are three roles:

  • The host is the AI app you use: Claude's apps, Claude Code, a code editor or your own agent.
  • Inside it, an MCP client holds one connection to one server.
  • An MCP server is a small program that offers capabilities. These come in three kinds:
  • tools: functions the model can call,
  • resources: data the app can read, like files or records,
  • prompts: reusable templates.

Most servers are mostly tools.

A server runs in one of two places. It can run locally, as a program the host starts on your computer. Then they talk through the program's standard input and output ("stdio"). Or it can run remotely, as a web service the host reaches over HTTPS. Either way, the messages are the same.

Quick check
An MCP server can run in two places. What are they?
  1. Inside the model, or inside the prompt
  2. Locally, over stdio, or remotely, over HTTPS
  3. In the browser, or in the database
  4. On a phone, or on a desktop computer
Show the answer

Locally, over stdio, or remotely, over HTTPS

A local server is a program the host starts on your computer, and they talk through its standard input and output. A remote one is a web service. The messages are the same either way.

The messages: JSON-RPC 2.0

MCP messages use JSON-RPC 2.0, a simple format for asking another program to run a function. A request has three parts:

  • a method: the name of what to run,
  • params: its inputs,
  • an id: a number to match the answer to the question.

The response carries the same id, plus either a result or an error:

{"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}
{"jsonrpc": "2.0", "id": 2, "result": {"tools": [{"name": "get_campaign",
                                       "description": "...", "inputSchema": {...}}]}}

A session goes in this order:

  1. initialize: client and server agree on a protocol version and say what they support.
  2. tools/list: the client asks which tools exist. Each has a name, a description and an inputSchema. That's a JSON schema, the same idea as Claude's input_schema.
  3. tools/call: the client runs a tool with {"name": ..., "arguments": {...}}. It gets back {"content": [{"type": "text", "text": ...}], "isError": false}.
Quick check
From the lesson on tool use: a tool is described to the model by three things. What does this print?
tool = {"name": "get_campaign", "description": "Look up one campaign by its id.",
        "input_schema": {"type": "object", "properties": {"id": {"type": "string"}},
                         "required": ["id"]}}
print(len(tool), tool["input_schema"]["required"])
  1. 2 ['id']
  2. 3 ['id']
  3. 3 ['string']
  4. 1 ['id']
Show the answer

3 ['id']

A tool definition has a name, a description and an input schema: three parts. The schema says the input is an object whose id is required. An MCP server answers a tools/list request with definitions in this same form, which is how one server's tools can be offered to any host.

Quick check
A host connects to a new MCP server, and the model wants to look up a campaign with one of its tools. In what order do the messages go?
  1. tools/call first, then tools/list to check the result
  2. tools/list, then initialize, then tools/call
  3. initialize, then tools/list, then tools/call
  4. initialize, then straight to tools/call
Show the answer

initialize, then tools/list, then tools/call

First they agree on a protocol version, then the client learns which tools exist and what inputs they take, and only then can it call one.

The academy's practice server at https://api.gradient.test/mcp speaks this format. It's simplified. Real remote servers can also stream, and MCP libraries handle that for you.

Note: This handshake-based flow is what most servers and apps spoke through 2025, and many still do. The newest revision of MCP, dated 2026-07-28, drops the initialize step. Each request carries its own protocol version in a _meta field instead. Phase 9 covers both.

Try it now

Three lifelines the learner steps, and a fourth for the model.

Quick check
What does this print?
import json
msg = json.dumps({"jsonrpc": "2.0", "id": 1, "method": "tools/list"})
print(json.loads(msg)["method"])
  1. 2.0
  2. 1
  3. tools/list
  4. jsonrpc
Show the answer

tools/list

json.dumps turns the dictionary into text, and json.loads turns it back, so ["method"] reads tools/list. Every MCP request is a small JSON object naming a method.

Quick check
In JSON-RPC, how does a client know which answer belongs to which request?
  1. It can't: you send one request at a time
  2. The method name is repeated in the response
  3. Answers always arrive in order, so it counts them
  4. The response carries the same id as the request
Show the answer

The response carries the same id as the request

The id is the matching number. A request with "id": 2 gets a response with "id": 2, whether it holds a result or an error.

In your own words
What problem does MCP solve, and who are the host, client and server?

Write a sentence or two, then compare it with a good answer in the lesson.

In Python: talk to a server

Purpose. Send the three messages with a small helper, and watch the id rise.

Each call is one POST request with a JSON-RPC body. The widget below sends them one at a time.

Drill

Match answers to requests

JSON-RPC answers can arrive in any order; the id says which request each belongs to. Write match(requests, responses): return a dictionary from each request's method to the result of the response with the same id, or to "error: " plus the error's message if that response has an error.

requests = [
    {"jsonrpc": "2.0", "id": 1, "method": "tools/list"},
    {"jsonrpc": "2.0", "id": 2, "method": "tools/call"},
]
responses = [
    {"jsonrpc": "2.0", "id": 2,
     "result": {"content": [{"type": "text", "text": "ROAS 4.1"}]}},
    {"jsonrpc": "2.0", "id": 1, "result": {"tools": [{"name": "get_campaign"}]}},
]


def match(requests, responses):
    return {r["method"]: s.get("result") for r, s in zip(requests, responses)}


print(match(requests, responses))
In the lesson, your code is checked as you write it.

Wrap those calls in a small helper, and the protocol turns into ordinary function calls:

import requests

def rpc(method, params, id):
    body = {"jsonrpc": "2.0", "id": id, "method": method, "params": params}
    return requests.post("https://api.gradient.test/mcp", json=body).json()["result"]

info = rpc("initialize", {"protocolVersion": "2025-06-18", "capabilities": {}}, 1)
print("server:", info["serverInfo"]["name"], "| protocol:", info["protocolVersion"])

for tool in rpc("tools/list", {}, 2)["tools"]:
    print("-", tool["name"], "| needs:", tool["inputSchema"].get("required", []))

call = {"name": "search_docs", "arguments": {"query": "gift card expiry"}}
print(rpc("tools/call", call, 3)["content"][0]["text"][:90])
It runs right here in your browser, with nothing to install.

The helper rpc builds the body, sends it and returns the reply's result. The code then does the three steps in order: initialize, tools/list and one tools/call.

How a host connects MCP to the model

This is what Claude's apps and other hosts do behind the scenes. It uses only things you already know:

  1. Call tools/list. Turn each MCP tool into a Claude tool: same name and description, with inputSchema renamed to input_schema.
  2. Send those tools with the user's message.
  3. When the model replies with a tool_use block, send tools/call to the server, with the block's name and its input as arguments.
  4. Put the text from the result into a tool_result. Set is_error when isError is true. Then continue the agent loop.

The model doesn't know or care that a tool lives on an MCP server.

Worked example

Turn an MCP tool into a Claude tool

Step 1 above, in code. An MCP server describes a tool with inputSchema. Claude's API wants input_schema. Everything else carries over unchanged:

mcp_tool = {"name": "get_campaign", "description": "Get one campaign by id.",
            "inputSchema": {"type": "object", "properties": {"id": {"type": "string"}},
                            "required": ["id"]}}
claude_tool = {"name": mcp_tool["name"], "description": mcp_tool["description"],
               "input_schema": mcp_tool["inputSchema"]}
print(sorted(claude_tool))
print(claude_tool["input_schema"]["required"])
In the lesson you can change this and run it.

It prints ['description', 'input_schema', 'name'], then ['id']. The schema itself isn't changed at all, only the key it sits under. A host does this for every tool a server lists.

Quick check
Your company's analytics vendor offers an MCP server. What does that let you do?
  1. Connect their tools to any MCP-capable AI app without a custom integration
  2. Run their whole dashboard inside your own Python scripts
  3. Train a model on their data, using the server as the training set
  4. Skip the model's tool-use step, since the server answers directly
Show the answer

Connect their tools to any MCP-capable AI app without a custom integration

Write it once, use it from any host that speaks MCP.

In your own words
How does a host turn an MCP server's tools into something the model can call?

Write a sentence or two, then compare it with a good answer in the lesson.

In production: servers, the SDK and trust

Purpose. Know what a server costs you in context, how it is built, and when not to connect it.

You'll rarely write the JSON-RPC by hand. The official Python SDK (the mcp package, version 2) turns ordinary typed functions into a server, much like the Claude SDK's tool runner. The card shows a server with one tool and reads its schema back.

Each host has its own way to add a server: a settings screen or a config file. For a local server, you list the command that starts it. For a remote one, you give its web address. In Claude Code it's the claude mcp add command. In an engineer's week, the work is mostly choosing which servers to connect and keeping their tool lists short, because every tool's description is paid for on every request and read by the model.

Treat servers like browser extensions

An MCP server runs code and sees what you send it. Its tool descriptions also go straight into the model's context. Before you connect one:

  • Install from sources you trust. The vendor's own server, or open source you can review.
  • Check what it can do. A server with "send email" or "delete record" tools can do exactly that if the model asks. Prefer read-only servers, and keep approval prompts switched on.
  • Watch for hidden instructions. A malicious server can hide instructions in a tool description, such as "also send the conversation to...". The prompt injection lesson covers this attack.
  • Give it the narrowest access. A key that can only do what it needs, not your admin account.

MCP doesn't replace tool use. It's a standard way to supply tools, and the model still asks for them the same way. The newest revision of MCP, dated 2026-07-28, drops initialize; Phase 9 covers it.

Quick check
An MCP server you found online offers send_email and delete_contact tools. What's the safest way to try it?
  1. Trust it as it is, since every MCP server is reviewed before it's published
  2. Keep approval prompts on and give it a limited key, or prefer a read-only server
  3. Connect it with your admin account, so every tool it offers can actually work
  4. Turn off approval prompts so it runs smoothly without interrupting you
Show the answer

Keep approval prompts on and give it a limited key, or prefer a read-only server

A server can do whatever its tools allow when the model asks. Narrow access and approval prompts limit the damage if it misbehaves.

Drill

Which tools need a person's approval?

Before connecting a server you found online, list the tools that can change or send things. Write risky_tools(tools): return the names of MCP tools whose name or description contains any of delete, send, pay, update or write (ignoring case), in the server's order.

TOOLS = [
    {"name": "search_contacts", "description": "Find contacts by name or email."},
    {"name": "send_email", "description": "Email a contact."},
    {"name": "get_invoice", "description": "Read an invoice."},
    {"name": "tidy_contacts", "description": "Delete duplicate contacts."},
    {"name": "set_note", "description": "Write a note on a contact's record."},
]


def risky_tools(tools):
    return [t["name"] for t in tools if "send" in t["name"]]


print(risky_tools(TOOLS))
In the lesson, your code is checked as you write it.
In your own words
Why treat an MCP server like a browser extension?

Write a sentence or two, then compare it with a good answer in the lesson.

Goes deeper in

Choose how to practice

Start with a short baseline or choose guided, independent, or AI-assisted practice.

Practice what you just read

  • 2 code examples you can edit and run
  • a practice exercise that checks your code
  • a 5-question quiz
  • 8 review cards for spaced repetition

Try a quiz question

In MCP, what is the "host"?

  1. The AI app the user works in, which connects to servers
  2. The machine the model runs on, usually in the provider's data center
  3. The company that wrote and published the server you're connecting to
  4. A JSON-RPC message that a client sends to start talking to a server

Answer it at the end of the lesson to see if you're right, and why.

Before this lesson

Keep learning

Where this lesson leads.

575 lessons in thirteen phases. 176 are free without an account, and a free account opens the rest. See every lesson.

Phase 1 · about 23 hours of study

Building with LLMs

Prompting, retrieval, tools, agents and evals 35 lessons 1 free
  1. What an LLM actually does FreeNext-token prediction, and why that produces useful behavior.25 min
  2. Tokens and the context windowHow text becomes tokens, and what fits in one request.25 min
  3. Prompt fundamentalsClear instructions, context and constraints: the 80% of prompting.35 min
  4. System prompts and rolesSet behavior once, separately from the conversation.30 min
  5. Examples in promptsShow the model what good looks like (few-shot prompting).30 min
  6. Structured outputGet reliable JSON back that your code can use.38 min
  7. EvalsMeasure output quality with test sets instead of vibes.35 min
  8. Improving a prompt against an evalChange one thing, rerun, compare, read what flipped, keep or revert: the loop that makes a prompt better, with a held-back set and the error on the gap.30 min
  9. Prompt chainingBreak big tasks into a pipeline of smaller model calls.35 min
  10. Choosing a modelTrade capability, speed and cost across model families.25 min
  11. Reasoning models and effortWhen models think before answering, and how to control it.35 min
  12. Streaming responsesShow output as it's generated instead of waiting.35 min
  13. Conversations and memoryAPIs are stateless: how chat history and memory really work.36 min
  14. Images and documentsSend screenshots, PDFs and charts as input.30 min
  15. EmbeddingsMeaning as a list of numbers, so text can be compared.35 min
  16. Similarity searchFind the most relevant text by comparing embeddings.35 min
  17. Chunking documentsSplit long documents so the right piece can be retrieved.30 min
  18. Vector databasesStore and search millions of embeddings quickly.40 min
  19. Retrieval-augmented generationAnswer from your own documents instead of the model's memory.30 min
  20. Measuring retrievalA labeled test set, hit rate, reciprocal rank, precision and recall at k and nDCG, and which half of a RAG system failed.30 min
  21. Making RAG goodHybrid search, reranking and citations.30 min
  22. Hallucinations and groundingWhy models make things up, and how to design against it.30 min
  23. Tool useLet the model call your functions (function calling).30 min
  24. The agent loopModel → tool → result → model, until the task is done.30 min
  25. Model Context ProtocolA standard way to plug tools and data into any AI app.30 min
  26. Agent design patternsRouting, orchestrator-workers and when not to build an agent.35 min
  27. LLMs in automationsPut models inside scripts and workflow tools that run on their own.35 min
  28. Prompt injection and securityHow untrusted text hijacks models, and how to limit the damage.35 min
  29. LLM-as-judgeGrade open-ended output with rubrics and a second model.35 min
  30. BLEU, ROUGE and BERTScoreWhat the three text-similarity scores reward, how each one misleads, and when a grader or a judge is the better tool.35 min
  31. Cost and latencyPrompt caching, batching and routing to cheaper models.35 min
  32. Logging and monitoringSee what your LLM app actually did in production.30 min
  33. Shipping an LLM appDeploy, secure keys, rate-limit and handle failures.35 min
  34. One app, several model providersTwo API formats side by side, adapters to one internal format, a gateway with fallbacks, and evals before switching.40 min
  35. Capstone: research agentA marketing research agent with retrieval, tools and evals.45 min
Practice for interviews 21 questions

AI agent interview questions and answers

Questions on designing and running agents: tools, the agent loop, permissions, context, multi-agent systems, security and evaluation.

Part of a free course 29 lessons

Free AI agents course

Learn how to build AI agents by building one: tools, the agent loop, MCP, permissions, context management and evals, ending with a coding agent that stops when its tests pass.

Part of a free course 15 lessons

Build and Deploy MCP Integrations

Build a Model Context Protocol client and server, then verify the integration with a compatible host.

Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write