Day 2 of 1460 minShell Walker

Day 2: MCP Explained: Servers, Tools and Trust

Taught by Mr Elite Updated

By the end of today you can

  • Explain what MCP is and how a client and server exchange JSON-RPC messages
  • Run a local sample MCP server and list its tools with a raw JSON-RPC call
  • Read a tools/list response and say what each tool can touch
  • Point to the trust boundaries in an MCP setup

Warm-up

Answer from memory first, then tap to check. Recalling yesterday is what makes it stick.

What are the parts that make an agent, beyond the model itself?

A system prompt, tools, and a loop that lets the model act repeatedly.

Why is a rule in a system prompt not a security control?

The model reads it as text alongside everything else, so it is a request that other text can override, not an enforced boundary.

Yesterday you saw that an agent is only as dangerous as the tools it holds. So where do those tools come from? In a growing number of setups, someone installs a package, points the agent at it, and a dozen new abilities appear: read files, query a database, send a message. The agent trusts what that package says about itself.

Today we open that package up. You will run a real MCP server on your own machine, talk to it by hand without any AI involved, and read exactly what it advertises. Once you can see the conversation, you can see where it can be attacked.

What MCP is and why it exists

MCP stands for Model Context Protocol. It is an open standard for connecting an AI application to outside tools and data. Before it, every agent framework had its own way of defining tools, so every integration was written again for each one. MCP is the common plug. Write a tool server once, and any MCP-aware application can use it.

The messages are JSON-RPC 2.0. That is just JSON with a fixed shape: a method name, some parameters, and an id so the reply can be matched to the request. If you have used curl and jq, you already have the skills to read it.

Host
The AI application the user runs, such as a chat app or coding agent. It contains the model.
Client
The part inside the host that holds one connection to one server.
Server
A separate program that offers capabilities. It can run locally or remotely.
Transport
How messages travel. Locally this is usually stdio, meaning the client starts the server and talks through its input and output. Remote servers use HTTP.

Quick check

In MCP, which component actually runs the code that reads a file or queries a database?

Tools, resources and prompts

A server can offer three kinds of thing. Knowing which is which tells you who is in control when something is used.

Tool
An action the model can ask to run, such as write_file. The model decides when to call it.
Resource
Data the application can load into context, such as a file or a record. Usually the application chooses, not the model.
Prompt
A reusable prompt template the user can pick, often from a menu.

Tools are where we will spend most of this course, because they act on the world. Every tool has a name, a plain-language description and an inputSchema, which is a JSON Schema describing the arguments it accepts. The model reads the name and description to decide whether to use the tool. Hold on to that sentence. It means a server writes text that the model trusts. We will exploit that on Day 7.

The conversation always starts the same way. The client sends initialize, saying which protocol version it speaks. The server replies with its own version and its capabilities. The client sends a notification called notifications/initialized. Only then can it ask for tools/list, and later call a tool with tools/call.

Watch me do it: list a server's tools by hand

We will use the official filesystem server from the MCP project. It lets a client read and write files inside one directory you name. Everything below runs on your own machine, inside a folder we create for the purpose. Nothing touches anything else.

bash
mkdir -p ~/mcp-lab/sandbox && cd ~/mcp-lab
echo "hello from the sandbox" > sandbox/notes.txt
node --version
Creates the working folder and a test file, then checks Node is installed. You need version 18 or higher.
bash
cd ~/mcp-lab
(
printf '%sn' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"day2-test","version":"0.1"}}}'
printf '%sn' '{"jsonrpc":"2.0","method":"notifications/initialized"}'
printf '%sn' '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
sleep 3
) | npx -y @modelcontextprotocol/server-filesystem ~/mcp-lab/sandbox > out.jsonl
You are acting as the MCP client. Message 1 introduces you, message 2 says you are ready, message 3 asks for the tool list. The server's startup note goes to the terminal; its JSON replies go to out.jsonl.
bash
wc -l out.jsonl
jq -c 'select(.id==2) | .result.tools[] | {name, description}' out.jsonl
select(.id==2) keeps only the tools/list reply. The rest walks the tools array and prints two fields from each tool.

Reading a tools/list response

Now look at the argument shapes, because they tell you what a caller can make the tool do. This command lists each tool with the names of the arguments it takes.

bash
jq -c 'select(.id==2) | .result.tools[] | {name, args: (.inputSchema.properties | keys)}' out.jsonl
Shows each tool name next to its argument names. A tool with a path argument can be pointed at a path. Ask who controls that value.

For each tool, I want you to ask three things. What does it read? What can it change? And who supplies the arguments? For read_file the answer to the last one is the model, and the model's choices are shaped by everything in its context, including text from untrusted places.

Also read the initialize reply in out.jsonl. It contains serverInfo and capabilities. A server that lists tools, resources or prompts there is announcing what it offers. Compare that to what tools/list actually returns.

Quick check

Which part of a tool definition does the model read to decide whether to use the tool?

Where trust boundaries sit

A trust boundary is a line where data or control passes between parties that should not trust each other equally. Draw your setup as a row of boxes and mark each line crossing.

Notice that the strongest boundary, the one that is actually enforced, is the server's own code and the permissions of the account it runs under. The filesystem server restricts itself to the directory you gave it. That restriction lives in code, not in a prompt. That is the kind of control we want, and we will test such limits on later days.

Your turn: annotate what each tool can touch

There is no hosted lab today. The practice is on your own machine, using the server you just ran. Open out.jsonl output in your editor and build a small table. This is the first draft of the threat map we build properly tomorrow.

text
tool            | reads         | changes        | arguments        | worst case
read_file       | any file in   | nothing        | path             | leaks a secret file in the folder
                | sandbox       |                |                  |
One example row to copy the style. Fill in one row per tool, in your own words.

If it did not work

Forgetting the notifications/initialized message and getting an error or no tool list

Send initialize, then the notification, then tools/list, in that order. Check out.jsonl for an error object.

Closing the pipe too early so out.jsonl is empty

Keep the sleep 3 line, and run the command a second time after the first download finishes. Raise the sleep if needed.

Treating the tool description as documentation only

Remember the model reads it as input. Read each description critically, as you would read untrusted data.

Pointing the server at a real folder such as your home directory to test it

Always use the sandbox folder while learning. Widen access only when you understand the risk.

Recap

  • MCP is a common protocol that lets any host connect to servers offering tools, resources and prompts
  • Messages are JSON-RPC 2.0, and a session runs initialize, notifications/initialized, then tools/list or tools/call
  • The server does the real work, and the model only chooses what to ask for
  • Tool names and descriptions are text the model trusts, which makes them an attack surface
  • Trust boundaries sit between user, model, client, server and the outside world
  • Real limits live in server code and account permissions, not in prompts

Cheat sheet

initialize
First request. Client and server agree on protocol version and capabilities
notifications/initialized
Client says it is ready. No reply expected
tools/list
Asks the server which tools it offers
tools/call
Asks the server to run one tool with arguments
inputSchema
JSON Schema describing a tool's arguments
jq -c 'select(.id==2)'
Picks the reply that matches request id 2
npx @modelcontextprotocol/inspector
Browser tool for exploring a server by clicking

Before the next day

Mission: Annotated tool map

Install and run the sample filesystem server, list its tools with a JSON-RPC call, and save the output with your own notes on what each tool can touch. Tomorrow we turn this into a full threat map, so the notes you write now are the raw material.

About 30 min

You are done when: A file day2-tools.txt containing the tools/list output with your annotations on every tool and a paragraph on trust boundaries.

Want more? Run the inspector as well, then compare its view with your raw JSON and note one thing each approach showed you that the other did not.

Quiz

4 questions. Your score is saved with your progress.

1. Why does MCP use a common protocol rather than each agent framework defining its own tools?

2. A tools/list reply shows a tool with a path argument. What is the most useful security question to ask?

3. Which statement about trust in an MCP setup is correct?

4. The filesystem server refuses to read outside its allowed folder. What does that tell you about where real limits live?

Finish the day

Mark the day complete to save your progress.

Go to Day 3

Next: Tomorrow we take the tool list you saved and build a proper threat map of an agent, marking every input, every tool and every privilege, so you can see where an attacker could get in.

Tell someone you are doing this:WhatsAppXLinkedIn

Your notes

Private to this device. Write what you want to remember from today.