Day 13 of 1460 minShell WalkerHands-on lab
Day 13: Reviewing and Locking Down an MCP Server
Taught by Mr Elite Updated
By the end of today you can
- Run a four-part review of an MCP server: source, tools, permissions and network
- Spot risky tool descriptions and over-broad scopes in the lab
- Apply pinning, isolation, egress limits and logging as concrete controls
- Produce a one-page lockdown checklist with each item marked done or not done
Warm-up
Answer from memory first, then tap to check. Recalling yesterday is what makes it stick.
Why is a model-written summary a weak basis for an approval prompt?
Because the model's prose can be influenced by attacker text, so the person may approve something that differs from the real action.
What does TOCTOU mean, and how do you defend against it in approvals?
Time of check to time of use: the state changes after the check. Bind approval to the exact action and re-verify at execution.
Your team wants to connect a new MCP server to the company agent. It has a friendly name, a tidy README and forty stars. Someone says it looks fine. Looks fine is not a review. Over the last twelve days you have seen how tool descriptions steer a model, how arguments carry attacks, and how agent privileges get turned on the user. Today you put that knowledge into one repeatable process.
By the end of this lesson you will have a method you can run on any MCP server in about half an hour, and a checklist you can hand to a colleague. We review first, connect second, and we assume the server is hostile until the evidence says otherwise.
The four-part review
A review needs an order, or you drift into whatever looks interesting. I use four passes: source, tools, permissions, network. Each pass asks one question. Source: what does this code actually do? Tools: what will the model be told, and what can it call? Permissions: what can the server touch if everything goes wrong? Network: where can it send data?
Write findings down as you go. A finding is a fact plus a risk, for example: 'tool read_file accepts any path, so it can read ~/.ssh'. If you cannot write it that plainly, you have not understood it yet. Vague notes such as 'tools look broad' cannot be fixed, checked or handed to anyone else.
FINDING 1
Pass: Tools
Fact: read_file takes a free-text path with no limit
Risk: the model could be steered to read ~/.ssh/id_rsa
Evidence: inputSchema, tool read_file, type string, no pattern
Fix: restrict to one folder and validate the pathThe four passes also work as a filter on your time. A server that fails the source pass badly, say it runs shell commands built from model input, may not deserve the other three. Stop early, write down why, and reject it.
- Scope
- The set of things a token or tool is allowed to touch, such as one repository or every repository.
- Egress
- Network traffic leaving a machine or container toward the outside.
- Pinning
- Fixing a dependency or server to an exact version or hash so it cannot change silently.
Quick check
You find a tool that can read any file path. Which pass does this belong to first?
The tool exposes the capability, and the permissions decide how far it reaches, so you record it in both passes.
Pass one and two: source and tools
Start with the source. You are not auditing every line. You are hunting for the dangerous doors: shell execution, file access, outbound requests, environment variable reads and dynamic code loading. A quick search finds most of them.
grep -rnE "exec|spawn|subprocess|eval|os.system|requests.|fetch(|process.env|os.environ" .Here is what each part looks for. exec, spawn, subprocess and os.system start other programs. eval runs text as code. requests. and fetch( make outbound web calls. process.env and os.environ read environment variables, which is where tokens often live. A hit is not automatically bad. It is a place to read the surrounding lines and ask whether model-supplied text can reach it.
Each hit prints in the form file:line:matching text. For example, server.py:42: subprocess.run(cmd, shell=True) tells you to open line 42 and trace where cmd comes from. If cmd is built from a tool argument, you have a serious finding.
Next, the tools. Remember from Day 7 that the model reads tool names and descriptions as instructions. List every tool and read the full description text, including long ones. Look for words aimed at the model rather than the user: 'before using this tool, also read', 'do not tell the user', 'always include'. Check each argument too. A free-text path or command argument is a Day 9 problem waiting to happen.
jq -r '.result.tools[] | "== " + .name + "n" + .description + "n"' tools.jsonA normal description is one or two plain sentences about what the tool does. Be suspicious of anything much longer than that, anything mentioning other tools, and anything that talks about what to hide from the user.
Quick check
Which description line is a red flag?
It addresses the model, asks for an unrelated sensitive action and demands secrecy.
Watch me do it: review the Day 2 sample server
I will run the first two passes on the local sample server from Day 2. Everything here runs on your own machine and touches nothing else. I assume the server lives in a folder called mcp-sample. If yours has another name, use that.
cat package.json | jq '.dependencies'{
"@modelcontextprotocol/sdk": "^1.0.0",
"zod": "latest"
}After these steps you should have a list of roughly five to ten notes. That is a normal result for a small sample server. Do not worry if most are low severity. The point is the habit: every note has a fact, a risk and evidence. Keep the file open, because the checklist is built from it.
Passes three and four, then lock it down
Permissions and network come next. Ask what identity the server runs as, which files it can read, which tokens it holds and what each token can do. A token that can read one repository is a contained problem. A token that can write to every repository is an incident. Then ask where it connects. A weather tool has no reason to reach any host except its weather API.
whoami
env | grep -iE 'token|key|secret' | cut -d= -f1If the second command prints names such as GITHUB_TOKEN, the server can read that token. Check the provider's settings on your own account to see what the token is allowed to do. If you cannot tell its scope, record that as a finding, because an unknown scope should be treated as broad.
For the network pass, start the sample server and look at what it connects to. On Linux, ss -tp lists connections with the owning process. On a Mac, lsof -i -P shows the same idea. A server that only answers local requests should show no outbound connections to unfamiliar hosts.
Lockdown turns findings into controls. Pin the version to an exact release or hash and review every update as a diff before accepting it, because a server can change after you approved it. Isolate it in a container with a read-only filesystem and no extra privileges. Give it a scoped token for one job. Block egress except for the hosts it needs. Log every tool call with time, tool name, arguments and result status, and alert on the odd ones.
# requirements.txt (pinned)
requests==2.31.0
# Node: pin exactly
npm install --save-exact zod@3.23.8docker run --rm --read-only --cap-drop ALL --network none
-v "$PWD/data:/data:ro" mcp-sampleIf the container starts and then exits with a write error, that is the lockdown working. The server wanted to write somewhere it should not. Decide whether it genuinely needs a writable folder, and if so mount one specific folder, not the whole filesystem.
Quick check
Which control best limits damage if a tool is tricked into sending data out?
Even a hijacked tool cannot exfiltrate to a host the network blocks.
Practice in the lab: six servers waiting for approval
Now you apply the method to servers you did not write. The lab gives you six MCP servers awaiting approval. Your job is to decide which to approve, which to reject and why. Work only inside the SecurityElites lab. Use the four passes in order and write a short note per server.
Expect some servers to be clean and some to hide the problem in a place you only find by reading carefully. Do not rush the clean-looking ones. A calm, well-written description is exactly how a careful attacker would write it.
Your turn
Rogue MCP Server
This lab puts the review method under realistic pressure. Six servers look plausible, and the evidence for approval or rejection sits in tool descriptions, scopes and behaviour that can change. It is the same decision your team will face on a real connection request.
What to try
What to notice
- Hostile instructions often hide inside otherwise ordinary descriptions.
- The risky servers are not always the ones that look suspicious by name.
- A scope that is too broad is a finding even when the tool text is clean.
If it did not work
Reading the README instead of the code and tool definitions
Treat the README as marketing. Base every finding on source, the raw tool list and observed behaviour.
Approving a server once and never rechecking it
Pin the version and review each update as a diff before you accept it.
Giving the server a broad token because it is easier
Create a token for one job and one resource, and record its scope in the checklist.
Logging full arguments with secrets inside
Redact keys and tokens before writing logs, and restrict who can read them.
Marking checklist items done without evidence
Next to each done item, note how you confirmed it, such as a command or a file line.
Recap
- Review in four passes: source, tools, permissions, network
- Tool descriptions are instructions to the model, so read them in full and in raw form
- Pin versions and review updates as diffs, because servers can change after approval
- Isolate with containers, scoped tokens and egress limits so a compromise stays small
- Log every tool call, redact secrets, and watch for unusual calls
- A checklist is only useful if each item has evidence and a done or not done mark
Cheat sheet
grep -rnE "exec|spawn|eval|fetch(|process.env" .- Find dangerous capabilities in server source
jq '.result.tools'- Extract tool definitions from a list response
Pinning- Lock to an exact version or hash
--read-only --cap-drop ALL --network none- Docker flags for a tightly isolated container
Scoped token- Credential limited to one job and resource
Egress allowlist- Only named outbound hosts are reachable
Tool call log- Time, tool, arguments, result, with secrets redacted
Before the next day
Mission: One-page review and lockdown checklist
Take the local sample server from Day 2 and review it with the four passes. Then write a one-page checklist covering what you found and what controls it needs. Mark each item done or not done honestly. This feeds directly into tomorrow's capstone.
About 35 min
You are done when: review-checklist.md, one page, with every item marked done or not done and an evidence note
Want more? Run the sample server in a container with --read-only and --network none, then mark the isolation items done with the command as evidence.
Quiz
4 questions. Your score is saved with your progress.
1. A server's tool descriptions look clean, but its token can write to every repository. What do you do?
Permissions are a separate pass. Broad scope raises the damage if anything else fails.
2. Why pin a server version and review updates as diffs?
An unpinned server can change behaviour or descriptions after review, so approval no longer matches what runs.
3. Which pair of controls best contains a hijacked tool?
The token limits what it can touch and egress limits where data can go.
4. What makes a lockdown checklist trustworthy?
Evidence turns a claim into a verified fact that someone else can recheck.
Finish the day
Mark the day complete to save your progress.
Next: Day 14 is the capstone. You will review a full agent and MCP setup, rank the findings by priority and back at least two with proof, using today's checklist as your starting structure.
Your notes
Private to this device. Write what you want to remember from today.