PTENES
MODULE 2.3

🔌 MCP Under the Hood

MCP (Model Context Protocol) is the pattern that gives AI “arms”: a single connection exposes many tools from a service (send, draft, search…), and the agent figures out which ones are available and decides which to call, when, and with what parameters. In this module, you’ll see how to install a server and where the API key goes (manually, in the file — never in chat), why you should prefer project-level config, and how to diagnose and control context cost.

7
Topics
~50
Minutes
Inter.
Level
Protocol
Type
Module progress 0% · 0 of 7

Without MCP, the AI can only chat. With MCP, it acts: reads emails, queries a database, searches a web page, sends a Slack message. The trick is that you don’t connect one action at a time—you connect a server (an entire service, such as email) and it already announces all its tools at once. The agent sees the menu and chooses the right dish for the request.

🤖 Agent coordinator 1 connection MCP server · Email exposes N tools ✉️ send email 📝 draft 🔍 search for a message the agent chooses which one to call

Illustrative diagram — one connection (the server) provides a set of tools. The agent reads what’s available and decides which tool to use for each request.

1

🧩 What the protocol solves

What it is

MCP (Model Context Protocol) is a common language for AI to communicate with external services. Instead of wiring up one action at a time, a single connection exposes many tools from that service. Think of an email service: when you connect the email server, the agent gets access to "send," "draft," and "search messages"—all at once.

What is it?MCP server — a small program that bridges the AI and a service (email, database, web), translating what each side understands. Tool — a concrete action the server provides (e.g., “send email”), with a well-defined name and parameters.

The protocol solves the problem of “how AI discovers and uses an action”: it standardizes tool descriptions. That’s how the agent can decide on its own which tool to call, when call and with which parameters. This is how AI gets "arms"—it goes from just chatting to actually acting in the world.

Why learn

Understanding MCP means understanding where your agent’s capabilities come from. Without that, it seems like "magic"—and magic is hard to debug. Knowing that each capability is a server with tools tells you what to install, what’s missing, and what to turn off.

  • •One connection, many actions: less configuration, more capability.
  • •Single standard: the same protocol works for email, databases, the web, etc.
  • •Foundation for the rest: the next topics only make sense once this is solid.

Key concepts

Protocol

Common language between AI and service.

1 → N

One connection, several tools.

AI arms

From conversation to action.

Server

Bridge to a service.

2

🤖 How the agent discovers and decides

What it is

As soon as the agent and MCP server connect, the agent begins to know all available tools from that server — names, descriptions, and parameters. From there, the decision is up to it: you describe the result in natural language ("send the team a notification"), and the agent chooses the right tool ("send message") and fills in the parameters.

What is it?Tool discovery — the moment when the agent reads the server’s “menu” and learns what it can do. Tool selection — the agent reasons about the request and decides which tool fits the goal.

request: “email the client” 🤖 Agent decides evaluates the tools ✉️ send email (selected) 📝 draft 🔍 search for a message runs with parameters

Illustrative diagram — you don’t say “use tool X.” You describe the result; the agent compares the request with its known tools and chooses the best one.

Why learn

Knowing the agent makes the decision changes how you ask: you focus on the result, not in pointing out the tool. And when it chooses incorrectly, you correct it with context ("don't draft it, actually send it") instead of micromanaging. This also explains why a server that's "on but useless" still gets in the way: your tools are added to the list the agent has to evaluate.

🎯 Practical tip

If the agent picks the wrong tool, don’t dictate its name—clarify the outcome: “I want it to reach the customer’s inbox now, not be saved as a draft.” Outcome descriptions guide the choice better than commands.

Key concepts

Discovery

Reads the menu when connecting.

Independent decision

The agent chooses the tool.

You → result

Describe the "what".

Parameters

It fills it in automatically.

3

🔑 .mcp.json and the key at hand

What it is

Installing an MCP server creates (or edits) a file .mcp.json: it stores the server configuration and, when the service requires authentication, a space reserved for the API key. You paste the key itself manually in the file. Never in chat, and never ask the agent to enter it for you.

What is it?API key (API key) — a password that proves you’re allowed to use a service. .mcp.json — the configuration file that lists the servers and how to start them. Placeholder — the “hole” where the key should go, marked for you to fill in.

🎯 Goal: manually paste the API key into .mcp.json

.mcp.json (edit the file)
{
  "mcpServers": {
    "firecrawl": {
      "command": "npx",
      "args": ["-y", "firecrawl-mcp"],
      "env": {
        "API_KEY": "<cole-sua-chave-aqui>"
      }
    }
  }
}

✅ How to verify: switch <cole-sua-chave-aqui> with your actual key, save the file and restart the assistant. The key stays only in the local file—outside the chat history.

Why learn

A key pasted into chat becomes part of the conversation history—which may be logged, shared, or leaked. Pasting it into the file keeps the secret where only you (and the program) can access it. This is a security rule, not a style preference: treat every key like a password.

✓ Key in .mcp.json (by hand)

  • ✓You paste the key directly into the configuration file.
  • ✓The secret stays local, outside the conversation history.
  • ✓You control who can see the file (and exclude it from version control).

✗ Key in chat

  • ✗Paste the key into a message for the agent.
  • ✗Ask the AI to “insert the key” for you.
  • ✗Leave the key in logs, screenshots, or shared conversations.

Key concepts

.mcp.json

Where the config lives.

Placeholder

Hole for the key.

By hand

You paste it, not the AI.

Never in chat

Key = password.

4

🏷️ Per project vs. global

What it is

MCP configuration can live in two scopes: global (applies to the whole machine; all projects can see it) or by project (.mcp.json stays inside the project folder and only applies there). The recommendation is to by project: it isolates the secrets and context for each job.

What is it?Global scope — configuration that applies everywhere on the machine. Per-project scope — configuration stored in the project folder that applies only while you work on it. Isolation — keep a project’s secrets and tools separate from those of other projects.

Global — one config for the whole machine global config project A project B project C ⚠ secrets leak between projects By project — each folder has its own .mcp.json 📁 project A your own .mcp.json 📁 project B your own .mcp.json ✓ Secrets and context isolated

Illustrative diagram — globally, one leak contaminates everything; per project, each job stays in its own bubble.

Why learn

Global configuration can trigger a security warning on every restart (the program warns that global servers are active for every project). The fix is to move the config into the project folder. Project by project, you also prevent one client from “seeing” another client’s tools and keys—less risk, less noise.

🎯 Practical tip

Tired of the security warning every time you restart? Move the servers block from the global config to the .mcp.json inside the project folder. The warning disappears, and each project carries only what it needs.

Key concepts

Global

Applies across the whole machine.

By project

Recommended; isolates.

Restart notification

Global can alert you.

Move to folder

The warning fix.

5

🔎 Where to find servers

What it is

MCP servers are found in two main places: MCP directories (sites that catalog servers, like mcp.so) and in the GitHub (search for "MCP server" + the name of the service you want). Before installing, look for the target service's server; then follow its README.

What is it?MCP directory — an online catalog of ready-to-use servers, organized by category. GitHub — where the servers’ code lives; the README usually includes the installation command and which variables (such as the key) to set.

Why learn

Knowing where to look saves you from reinventing the wheel: in most cases, the server you need already exists. Knowing the common categories also speeds up the search—you know there's something for web scraping, databases, documents, and communication, so you go straight to it.

Common server categories

🕸️ Web scraping

E.g.: Firecrawl — read web pages.

🗄️ Databases

E.g.: Postgres, Supabase.

📄 Documents

E.g.: Google Drive, Notion.

💬 Communication

E.g.: Slack, Gmail.

🎯 Practical tip

Quick search: on GitHub, search for MCP server + the service name (e.g., MCP server notion). Prefer repositories with more stars and a clear README — they tend to be better maintained and safer.

Key concepts

Directories

Catalogs such as mcp.so.

GitHub

"MCP server" + service.

Categories

Web, database, docs, chat.

Already exists

Don't reinvent the wheel.

6

🩺 Check and diagnose

What it is

The command /mcp lists the installed servers and the status for each one (connected, with an error, etc.). That’s your "MCP health." And there’s a golden rule for diagnosis: if a newly installed server doesn’t appear in the list, restart the assistant first — that solves it most of the time.

What is it?/mcp — command that shows the servers and their status. Restart — close and reopen the assistant so it rereads the configuration; many servers only “appear” after that.

🎯 Goal: check the connected MCP servers

command (copy and run)
/mcp

✅ How to verify: the list shows each server and its status; if a new server doesn’t appear, restart the assistant and run /mcp again.

The complete sequence, step by step

1

Install the server

Find it in the directory/GitHub and follow the README. This generates or edits the .mcp.json.

2

Check the config

See the server block in the .mcp.json (preferably by project).

3

Paste the key manually

Replace the placeholder with the API key—in the file, never in chat.

4

Restart the assistant

Close and reopen to reread the configuration and load the server.

5

Verify with /mcp

Run /mcp; the server should appear connected. If it doesn’t, go back to step 4.

Why learn

Without the /mcp, you’re left in the dark: you don’t know whether the server connected, failed, or wasn’t even read. And without the habit of restarting, you waste time “fixing” what isn’t broken. Restarting is the first step for any MCP troubleshooting—cheap, fast, and almost always enough.

Key concepts

/mcp

List servers + status.

Status

Connected? Error?

Restart first

Works in most cases.

Didn't show up?

Restart, run /mcp.

7

💸 Context cost

What it is

Each server active injects your tool definitions into the context from AI — and that consumes tokens. More connected servers mean more text the model has to read before responding, even if you don’t use any of them. The rule: turn off the servers you're not using to free up context.

What is it?Context — everything the AI “has in its head” during the conversation (your message + instructions + tool definitions). Token — a small piece of text the model counts; more text = more tokens = more cost and more noise.

Everything connected — context packed with definitions tools server A tools server B tools server C server D little room for conversation Only what’s necessary — leaving context free tools in use free space to reason and respond

Illustrative diagram — each server connects a block of definitions. Fewer blocks mean more room for the AI to think, lower costs, and less noise.

Why learn

Cluttered context has three costs: it uses more tokens (more expensive), confuses the agent (more tools to evaluate means a greater chance of choosing the wrong one), and slows everything down. Keeping only the servers needed for the current task active is the simplest way to reduce cost and errors at once.

✓ Turn off unused servers

  • ✓Keep only the servers for your current work active.
  • ✓Frees up context: fewer tokens, lower cost.
  • ✓Fewer tools to evaluate = more reliable choices.

✗ Leave everything on all the time

  • ✗Accumulating servers you don’t even use in that project.
  • ✗Paying for tokens for idle tool definitions.
  • ✗More noise = more chances the agent will choose the wrong tool.

🎯 Practical tip

Do a periodic “cleanup”: run /mcp, check the list and turn them off (or remove them from the .mcp.json) everything that isn’t part of the current project. Less noise = fewer errors + lower cost.

Key concepts

Token cost

Each defined tool adds weight.

Noise

More tools, more errors.

Turn off

What’s not in use, off.

Frees up context

More room to think.

You installed a server and an API key. Where does the key go—and what should you do if the server doesn’t appear in the /mcp?

📌 Module Summary

✓
What MCP solves — one connection exposes many tools from a service; it’s how the AI gets “arms.”
✓
Discovers and decides — when connected, the agent knows all the tools and chooses on its own; you describe the outcome.
✓
Key entered by hand in .mcp.json — installation generates the config with a placeholder; paste the key into the file, never in chat.
✓
By project > global — project-level config isolates secrets; moving the global config into the folder resolves the security warning.
✓
Where to find servers — directories (mcp.so) and GitHub; categories: web, databases, documents, communication.
✓
Verify and diagnose — /mcp lists servers and their status; if a new one doesn’t appear, restart first.
✓
Context cost — each active server uses tokens; turn off unused ones to free up context.

Next Module:

2.4 — Context & Tokens