How to secure an assistant that loads tools from MCP servers
Keep one reviewed config file in which every server is pinned to an exact version, declares its own environment, and receives only the secrets it needs by reference. Launch each local server with that environment and nothing else, and put servers that run code you did not write in a sandbox. In the runs below, a launcher that passed the whole parent environment gave every server every secret and a readable copy of the others' token files; a scoped environment closed the first and a bubblewrap sandbox closed the second.
Updated 29 Nov 2026
What this assistant can reach
The host application starts or connects to MCP servers, loads their tool descriptions into the model's context, and passes tool results back. In the stdio transport, "the client launches the MCP server as a subprocess".1 A local server therefore runs as you, with whatever environment the launcher gives it and whatever files you can read. A remote server gets whatever token its configuration carries. Tool descriptions and tool results are both text the model reads, so a poisoned or silently changed tool can steer every other tool in the session. OWASP's third-party MCP guide names tool poisoning and rug pulls, prompt injection and others, and recommends pinning, containers and least-privilege policy at the server boundary.2
Threats and controls for this shape
Capabilities: Reads content it does not control; Calls tools, APIs or MCP servers; Holds credentials or sessions.
Threats that apply (12)
Prompt injection and goal hijack
OWASP Agentic v1.1: T6; OWASP Agentic 2026: ASI01; OWASP LLM 2025: LLM01:2025; OWASP LLM 2026: LLM01:2026; MITRE ATLAS: AML.T0051, AML.T0051.000, AML.T0051.001, AML.T0051.002, AML.T0054, AML.T0065, AML.T0068, AML.T0093, AML.T0094, AML.T0099, AML.T0100, AML.T0129, AML.T0130, AML.T0131, AML.T0134; NIST AI 600-1 section 2.9
Tool misuse
OWASP Agentic v1.1: T2; OWASP Agentic 2026: ASI02; MITRE ATLAS: AML.T0053, AML.T0101
Privilege and credential abuse
OWASP Agentic v1.1: T3; OWASP Agentic 2026: ASI03; MITRE ATLAS: AML.T0082, AML.T0083, AML.T0098
Excessive agency
OWASP LLM 2025: LLM06:2025; OWASP LLM 2026: LLM03:2026
Sensitive data disclosure
OWASP LLM 2025: LLM02:2025; OWASP LLM 2026: LLM02:2026; NIST AI 600-1 section 2.4; MITRE ATLAS: AML.T0085, AML.T0085.000, AML.T0085.001, AML.T0085.002
System prompt and agent configuration disclosure
OWASP LLM 2025: LLM07:2025; OWASP LLM 2026: LLM08:2026; MITRE ATLAS: AML.T0002.002, AML.T0006.003, AML.T0069, AML.T0069.000, AML.T0069.001, AML.T0069.002, AML.T0084, AML.T0084.000, AML.T0084.001, AML.T0084.002, AML.T0084.003, AML.T0085.003, AML.T0133
Data exfiltration through tool calls and rendered output
MITRE ATLAS: AML.T0086, AML.T0077, AML.T0067.001
Repudiation and untraceable actions
OWASP Agentic v1.1: T8
Tool, MCP server and supply chain compromise
OWASP Agentic v1.1: T17, T16; OWASP Agentic 2026: ASI04; OWASP LLM 2025: LLM03:2025; OWASP LLM 2026: LLM04:2026; NIST AI 600-1 section 2.12; MITRE ATLAS: AML.T0010.005, AML.T0011.002, AML.T0017.002, AML.T0060, AML.T0062, AML.T0081, AML.T0110, AML.T0110.000, AML.T0110.001, AML.T0110.002, AML.T0115.002
Resource overload and unbounded consumption
OWASP Agentic v1.1: T4; OWASP LLM 2025: LLM10:2025; OWASP LLM 2026: LLM06:2026; MITRE ATLAS: AML.T0034.002
Human manipulation and false action summaries
OWASP Agentic v1.1: T15; OWASP Agentic 2026: ASI09; MITRE ATLAS: AML.T0067, AML.T0067.000, AML.T0067.002, AML.T0067.003; NIST AI 600-1 section 2.7
Overwhelming the human in the loop
OWASP Agentic v1.1: T10
Controls in order (14)
Why here: It costs nothing to build and changes what every later control has to protect. Deleting a capability beats guarding it.
Why here: An agent acts with some credential: one given for its tools, its host's or the user's when it has none of its own, or the authority it passes on when it talks to other agents. Scoping that credential and giving it a short life caps the damage from every other failure: a hijacked agent can only do what the credential allows, for as long as it lives.
Why here: Anything in the prompt, memory or tool results can be repeated back by the model or read by an attacker who finds a way to ask. Keep secrets where the model cannot see them before anything else is exposed.
Why here: It removes the exit. An injected instruction that cannot send data anywhere has little to steal for, even when the earlier controls fail.
Why here: After credentials and network are bounded, the next question is which actions the agent may take at all (tool calls, browser actions, code it runs) and with which arguments.
Why here: What the agent loads is trusted by default. Pinning turns a silent change into a visible one.
Why here: MCP servers are a common way third-party code and text enter the agent, and the checks differ from plain API tools.
Why here: The earlier controls limit what a hijacked agent can do; this one reduces how easily it is hijacked and keeps a hijack from spreading.
Why here: Model output goes into other systems; once inputs and actions are bounded, the last gap is what those systems do with it.
Why here: After the actions are bounded and checked, a person decides on what is left that is irreversible or high-impact.
Why here: Limits on volume protect availability and budget and slow an attacker, but they do not stop a single harmful action, so they come after the controls that do.
Why here: Detection and investigation come after containment. Logs do not stop an attack but make the other controls testable and the incident explainable.
Why here: Response needs logging to know what to undo and controls in place to make stopping safe. It is the last control to build and the first one used in an incident.
Why here: It checks that every other control works, and it has to be repeated whenever the agent, its tools or the model change.
This page covers the client configuration that ties those controls together and tests the one thing those pages do not: whether one server can see another server's secrets.
The config file
mcp.json uses the mcpServers shape with command, args and env that MCP clients commonly read. A value can reference a variable as ${VAR}, so the file holds no secret and can be reviewed and committed.
{
"mcpServers": {
"alpha": { "command": "node", "args": ["server.mjs", "alpha"], "env": { "ALPHA_TOKEN": "${ALPHA_TOKEN}" } },
"beta": { "command": "node", "args": ["server.mjs", "beta"], "env": { "BETA_TOKEN": "${BETA_TOKEN}" } },
"everything": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-everything@2.4.0"],
"env": {}
}
}
}
alpha and beta are two small servers written for the test; everything is the published reference server from the MCP project, pinned to the exact version 2.4.0. Three habits show in the file: an exact version in the package argument, an env block on every server (an empty one for a server that needs nothing), and each secret named in one server's block only.
Lint the file
check_config.py fails a config on five rules: R1 an npx, uvx, bunx or pipx package without an exact version; R2 a server with no env block; R3 a secret-named variable with a literal value; R4 one variable passed to more than one server; R5 a shell as the launcher. It ran on a deliberately bad file and on mcp.json:
$ ./check_config.py mcp.bad.json
FAIL R1 alpha: package '@modelcontextprotocol/server-everything@latest' is not pinned to an exact version
FAIL R3 alpha: ALPHA_TOKEN holds a literal value in the config file
FAIL R1 beta: package '@modelcontextprotocol/server-memory' is not pinned to an exact version
FAIL R1 gamma: package 'mcp-server-fetch>=0.5' is not pinned to an exact version
FAIL R2 gamma: no env block (inheritance is then up to the client)
FAIL R5 delta: launcher is a shell (bash); the command is not reviewable
FAIL R4 beta, delta: ALPHA_TOKEN is passed to more than one server
7 problem(s)
exit=1
$ ./check_config.py mcp.json
config OK
exit=0
An exact version fixes what you approved; it does not prove the package is unchanged under that version. For that, record the package hash and the hash of each tool definition and compare at every start, as in tool supply chain pinning. OWASP's guide says the same in two parts: pin the server and tool version at first approval, and "use checksums to verify integrity and prevent silent, malicious upgrades".2
Test: can one server see another's secrets?
The test starts each server over stdio from the same config, calls its probe tool, and reports what it can see. The parent process holds three fake secrets (ALPHA_TOKEN, BETA_TOKEN, HOST_SECRET) and the home directory holds ~/.config/alpha/token and ~/.config/beta/token. The probe reports three things for each server: another server's token in its environment, HOST_SECRET in its environment, and whether it can read the other server's token file. The client is the MCP TypeScript SDK 1.32.2. Its getDefaultEnvironment() passes only HOME, LOGNAME, PATH, SHELL, TERM and USER on Linux and macOS ("Environment variables to inherit by default, if an environment is not explicitly given"),3 and client.mjs merges that list with the server's own declared variables in the scoped mode. Three launch policies ran:
inherit-all: the child gets the parent's whole environment plus its declared variables. This is the shape of a launcher script that exports everything and starts every server. It is not a claim about any named client; check yours with this test.scoped: the child gets the default safe list plus its own declared variables.scoped+bwrap: scoped, started under bubblewrap (--clearenv, a read-only view of the filesystem, the home directory replaced by an empty tmpfs, and only that server's own config directory bound back in).
$ node client.mjs inherit-all
server alpha
ATTACK SUCCEEDED sees the other server's token in its environment (BETA_TOKEN)
ATTACK SUCCEEDED sees the host's HOST_SECRET in its environment
ATTACK SUCCEEDED reads the other server's token file (READ)
env: 171 variables
server beta (the same three, ALPHA_TOKEN)
$ node client.mjs scoped
server alpha
blocked sees the other server's token in its environment (BETA_TOKEN)
blocked sees the host's HOST_SECRET in its environment
ATTACK SUCCEEDED reads the other server's token file (READ)
env names it has: ALPHA_TOKEN HOME LOGNAME NODE_DIR PATH SHELL USER
server beta (the same three, ALPHA_TOKEN)
$ node client.mjs scoped+bwrap
server alpha
blocked sees the other server's token in its environment (BETA_TOKEN)
blocked sees the host's HOST_SECRET in its environment
blocked reads the other server's token file (ENOENT)
env names it has: ALPHA_TOKEN HOME LOGNAME NODE_DIR PATH PWD SHELL USER
server beta (the same three, ALPHA_TOKEN)
(NODE_DIR is a test variable that tells the servers where to find the SDK; PWD is added by bubblewrap, which unsets all variables except PWD and those set by --setenv.4)
The pattern is the point. Scoping the environment removes the secrets the server was never given, which is most of the exposure. It does not remove files: both local servers run as the same user, so alpha reads beta's token file until something stops it. bubblewrap does. Its README says it "is not a complete, ready-made sandbox with a specific security policy", so the mounts above are a policy this test chose, and a container with the same effect (sandboxed code execution) is the more usual form; OWASP's third-party MCP guide says to "Use Containers (e.g. Docker) to run third-party MCP servers".25
A published server you did not write, under the same two policies
everything.mjs starts the pinned @modelcontextprotocol/server-everything@2.4.0 exactly as mcp.json names it and calls its get-env tool, which returns the server process's environment (pinned-server-*.log):
$ node everything.mjs inherit-all
server: mcp-servers/everything 2.4.0
environment printed by the server: 195 variables
ATTACK SUCCEEDED ALPHA_TOKEN visible to the server
ATTACK SUCCEEDED BETA_TOKEN visible to the server
ATTACK SUCCEEDED HOST_SECRET visible to the server
$ node everything.mjs scoped
environment printed by the server: 30 variables
blocked ALPHA_TOKEN visible to the server
blocked BETA_TOKEN visible to the server
blocked HOST_SECRET visible to the server
The 30 variables under scoped are mostly npm_* variables (by inspection; the log prints only the count) plus the default list; none is one of the three secrets. The same pattern holds for a server you did not write: whatever is in its environment, the server (and anything an attacker gets it to run) can read and return to the model.
Remote servers
A remote server has no environment to scope: its credential is a header or token the client sends. The same rule applies in other words: one token per server, with an audience of that server only, never the same token for two servers, and never forwarded onward. A headers value that references a variable (headers: { "Authorization": "Bearer ${API_KEY}" }) keeps the token out of the file, and MCP server and client hardening tests the audience check. This page's runs cover local stdio servers only.
Evidence to keep
- The config file as deployed, and the lint output for it (exit 0).
- The list of approved servers with exact versions and the date each version was approved and by whom, kept next to the hashes from tool supply chain pinning.
- The output of the secret-visibility test against the deployed launcher, with every line
blocked, and the get-env result for each third-party server. - A diff review record for each version bump of a server.
Where this stops
- A server can still do what its tools do. Scoped environment and sandbox limit what a server can read. A tool that is allowed to send mail still sends mail; limit tools and arguments (tool allowlist and argument validation) and gate consequential calls (human approval gates).
- Tool results are text the model reads. An allowed server that returns a web page or an email returns whatever its author put there: untrusted content isolation.
- A server needs its own secret. The server that talks to a mail system holds a mail credential, which a compromised copy of it can use. Make that credential narrow and short-lived: scoped, short-lived credentials.
- Network. The bubblewrap run does not unshare the network, so a server can still send what it can read. Add egress allowlist.
- Clients differ. Whether a client passes the whole environment to servers, and how it gates servers that a cloned repository's
.mcp.json adds, is client behavior to test. A reviewed list matters for that reason. - Versions are pinned at approval, not forever. Re-check on a schedule and on every bump, and keep a way to turn a server off quickly: kill switch and rollback.
Files
In /runs/shape-mcp-connected-assistant/: mcp.json, mcp.bad.json, check_config.py, server.mjs, client.mjs, everything.mjs, run_all.sh, package.json and package-lock.json (SDK 1.32.2 and server-everything 2.4.0), and the logs lint-bad.log, lint-good.log, env-scope-inherit-all.log, env-scope-scoped.log, env-scope-scoped+bwrap.log, pinned-server-inherit-all.log, pinned-server-scoped.log. Environment: Node 22.23.5, npm 10.9.9, bubblewrap 0.11.1, Python 3.14.4, run 29 Nov 2026.
Sources
- Transports (stdio), Model Context Protocol specification 2025-06-18, https://modelcontextprotocol.io/specification/2025-06-18/basic/transports, read 29 Nov 2026
- A Practical Guide for Securely Using Third-Party MCP Servers v1.0 (23 Oct 2025), OWASP GenAI Security Project, https://genai.owasp.org/download/51928/?tmstv=1762283701, read 29 Nov 2026
- @modelcontextprotocol/sdk 1.32.2, file dist/esm/client/stdio.js (
DEFAULT_INHERITED_ENV_VARS, getDefaultEnvironment), MCP TypeScript SDK, https://github.com/modelcontextprotocol/typescript-sdk, read from the installed package 29 Nov 2026 - bwrap manual (bwrap.xml), bubblewrap, https://github.com/containers/bubblewrap/blob/main/bwrap.xml, read 29 Nov 2026
- bubblewrap README, https://github.com/containers/bubblewrap/blob/main/README.md, read 29 Nov 2026