Local MCP Server Security: Docker, Scopes and Least Privilege
Local MCP server security in practice: what a stdio server inherits, pinning npx, uvx and image versions, docker run flags, directory scopes, secrets.
Cet article est en anglais.
TL;DR. A local MCP server is a child process of your own user account: it inherits your environment variables, reads whatever you can read and opens outbound connections wherever it likes. Local MCP server security therefore happens before launch, in what you install and how you start it. Pin the exact package or image digest, run third-party servers in a container with only the directory they need mounted (read-only where possible), pass each server its own narrow credential, and remove network access when the server only works on local files. mcp.tc marks which listings run locally and records their published npm and PyPI versions on each listing's History tab; it never runs a local server itself.
What can a local MCP server reach on your machine?
A local MCP server over stdio is an ordinary operating system process that your MCP client launches, and it holds every permission your user account holds. The protocol draws no boundary between a client and the server it spawned, so files, environment variables and the network stay open to the server until you close them yourself.
The 2026-07-28 stdio binding says "the client launches the MCP server as a subprocess" and the two talk over stdin and stdout. The server "MAY write UTF-8 strings to stderr" for logging and "MUST NOT write anything to its stdout that is not a valid MCP message". Shutdown starts with the client closing the input stream. Nothing in that binding says what the subprocess may touch, because the transport has no way to enforce it.
The MCP project's own Local Server Security guide states the consequence plainly: "the client and a stdio server share one trust domain" and "The stdio transport is not a sandbox." It lists five threats: a malicious server (typosquatted names, lookalike repositories, a project taken over by a new publisher), an overcollecting server, a compromised dependency, a poisoned tool catalog, and a vulnerable server or bridge. Its principle for all five is to treat a third-party local server as untrusted code with exactly the privileges you hand it, and to hand it as few as possible.
Each section below is one privilege you can decline to hand over.
Does the server need to run locally at all?
The cheapest way to contain a local MCP server is to not install one: a server that only wraps an API on the internet gains nothing from running on your laptop, and the official guide says a server offered over Streamable HTTP "runs no code on your machine". Local installs are for servers that need your working tree, a local tool or hardware.
The guide puts the test as a question about access: reading your files, driving a local program or reaching a device are reasons to run locally; wrapping a remote service is not. It also suggests treating an unnecessary local install as a signal worth a second look, since that is exactly how an overcollecting server gets onto a machine.
On 22 November 2026, mcp.tc listed 1,633 public MCP servers: 1,290 remote and 343 that run locally. The directory has a filter for servers that run locally, and every listing says on its page whether the server is remote or local and whether it needs sign-in. If you are weighing the two models for a specific job, the earlier post on remote vs local MCP servers goes through the tradeoffs.
How do I pin a local MCP server's version?
Pinning a local MCP server means naming an exact package version or image digest in the client config, so a future release does not arrive through the launcher without your knowledge. With npx and uvx the version goes after an @; with Docker the digest replaces the tag.
The npx docs give the synopsis npx -- <pkg>[@<version>] [args...] and say that npx "prompts before installing anything" to prevent "security and user-experience problems from mistyping package names". The -y flag suppresses that prompt, which is why most client configs carry it; the MCP docs' own local server quickstart explains -y as "Automatically confirms the installation of the server package". A pinned entry looks like npx -y example-server@1.4.2. To see what versions exist before you choose one, run npm view example-server versions, following the npm view docs.
For Python servers, the uv tools guide says uvx "invokes a tool without installing it" into "temporary, isolated environments", and a version is requested as command@<version>. The guide notes that the @ syntax "cannot be used for anything other than an exact version"; ranges go through --from.
One limit matters here. The Local Server Security guide warns that pinning with a launcher such as npx or uvx "fixes only the top-level package" while its transitive dependencies "are typically resolved fresh at install time, which is exactly where a compromised dependency arrives". Pinning a container image by digest freezes the whole tree. The docker pull reference shows the form docker pull ubuntu@sha256:... and adds that Docker "does therefore not pull updated versions of an image, which may include security updates". A pin is a decision to update on purpose, so pair it with a way to hear about new releases.
mcp.tc helps with that last part for local servers. Every 3 hours it checks the npm or PyPI package of each local listing for a new version and records version numbers on the listing's History tab (at most one version change a day); the Follow button sends an email when a followed listing's version goes up. The pinning guide covers the per-ecosystem syntax in more depth.
How do I run an MCP server in Docker with least privilege?
Running a local MCP server in a Docker container keeps the stdio transport unchanged while replacing your home directory, shell environment and keychain with an empty filesystem and a handful of flags you choose. The client launches docker instead of npx, and docker run -i keeps stdin open so the protocol still flows.
The flags below come from the docker run reference and the container runtime docs:
| Flag | What Docker's docs say it does | Why it matters for an MCP server |
|---|---|---|
-i | "Keep STDIN open even if not attached" | stdio needs a live stdin |
--rm | "Automatically remove the container and its associated anonymous volumes when it exits" | no leftover state between launches |
--read-only | "Mount the container's root filesystem as read only" | the server cannot modify its own image |
--tmpfs /tmp | "Mount a tmpfs directory" | scratch space that disappears on exit |
--cap-drop ALL | "Drop Linux capabilities"; both flags "support the value ALL" | removes the default capability set |
--security-opt no-new-privileges=true | "Disable container processes from gaining new privileges" | blocks setuid-style escalation |
--user 10001:10001 | "Username or UID"; "The default user within a container is root (uid = 0)" | avoids running as root inside the container |
--memory 256m, --pids-limit 100 | "Memory limit"; "Tune container pids limit" | caps runaway processes |
--network none | isolates the networking stack; "only the loopback device is created" | no egress (see below) |
A full command for a server that reads one project directory:
docker run -i --rm \
--network none \
--read-only --tmpfs /tmp \
--cap-drop ALL \
--security-opt no-new-privileges=true \
--user 10001:10001 \
--memory 256m --pids-limit 100 \
-v "$HOME/projects/example:/data:ro" \
example/example-server@sha256:<digest> /dataThe --user line assumes the image can run as an arbitrary non-root UID; drop it if the image documents a different user. The same command goes into a client config as command and args. The mcpServers shape and the config paths below come from the MCP docs' local server quickstart: ~/Library/Application Support/Claude/claude_desktop_config.json on macOS, %APPDATA%\Claude\claude_desktop_config.json on Windows and ~/.config/Claude/claude_desktop_config.json on Linux.
{
"mcpServers": {
"example-server": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"--network", "none",
"--read-only", "--tmpfs", "/tmp",
"--cap-drop", "ALL",
"--security-opt", "no-new-privileges=true",
"-v", "/Users/username/projects/example:/data:ro",
"example/example-server@sha256:<digest>",
"/data"
]
}
}
}Paths in a client config must be absolute; the quickstart's troubleshooting section lists relative paths among the reasons a server does not show up. The official guide calls process isolation "the single highest-leverage mitigation" in its list, and also says a container "is not an impenetrable boundary". It removes the default access that common attacks rely on; a seccomp profile, AppArmor or SELinux, a separate user account or a microVM go further.
How do I limit which directories a server can see?
Limiting a local MCP server to specific directories takes two layers: the directory you pass the server in its arguments or configuration, which a well-behaved server honors, and a mount that makes that directory the only filesystem the process can see, which holds even when the server does not honor anything.
The 2026-07-28 specification changed the first layer. Roots, the client feature that told servers which directories were relevant, are deprecated as of 2026-07-28 under SEP-2577. The page says they remain in the specification "for at least twelve months" and that existing implementations "SHOULD migrate to passing directories or files via tool parameters, resource URIs, or server configuration". It also describes roots as "informational guidance rather than an access-control mechanism" and states that "The protocol does not enforce that servers stay within roots." The changelog lists the same deprecation alongside Sampling and Logging, under a lifecycle policy with a minimum twelve-month window.
So the directory list lives in the server's own arguments, as in the quickstart config where "The remaining arguments: Directories the server is allowed to access". The quickstart's warning applies to every such server: "The server runs with your user account permissions, so it can perform any file operations you can perform manually." The Local Server Security guide calls these lists "cooperative boundaries": a well-behaved server respects them, and "nothing in the protocol stops a malicious or compromised one from reading whatever the process can reach".
Enforcement is the mount. In the bind mount docs, adding ro after the container path, as in -v "$(pwd)"/target:/app:ro, mounts the directory read-only; --mount type=bind,...,readonly does the same. Grant the narrowest directory that works, never your home directory, and prefer read-only when the server's job is to read code or documents. Inside the container, pass the mounted path (/data above) to the server as its allowed directory, so both layers agree.
How do I keep credentials out of a server's reach?
A local MCP server may inherit the environment of whatever launched it, so credentials exported in a shell profile are readable by every server you run. The fix is per-server environment entries in the client config, each holding a token scoped to one server, with long-lived secrets kept out of plaintext files where the client allows.
In Claude Code, the MCP docs give the form claude mcp add [options] <name> -- <command> [args...], with --env KEY=value for each variable. The docs add a placement rule: if the server name comes directly after --env, the CLI reads the name as another pair, so put an option such as --transport stdio between them.
claude mcp add --env EXAMPLE_API_KEY=YOUR_KEY --transport stdio example-server \
-- npx -y example-server@1.4.2For a shared project, Claude Code's project scope writes .mcp.json at the project root, and that file supports ${VAR} and ${VAR:-default} expansion in command, args, env, url and headers. The token then stays in each developer's environment rather than in the committed file.
VS Code's MCP configuration reference documents an inputs array for "sensitive information like API keys": an entry of type promptString with an id, a description and password: true ("Hide typed input"), referenced in env as ${input:example-key}. VS Code "prompts you for the value when the server starts for the first time" and the value "is then securely stored for subsequent use". The same page places this inputs form, and the servers format of .vscode/mcp.json, under the editor-managed configuration of the Local harness, which it says "is deprecated and will be removed in February 2027"; for new Copilot configurations it points to ~/.copilot/mcp-config.json and a workspace-root .mcp.json, where a secret is referenced as ${NAME}.
Files are credentials too. ~/.ssh and ~/.aws are readable by any bare process you run; the container section above is what keeps them out of reach. And scope each token narrowly, so a leak from one server is contained and revocable without touching the others.
When should a server have no network access?
A local MCP server that works on local files or tools needs no network, and removing it closes the only exit a compromised or overcollecting server has. Docker's none network driver isolates the container's networking stack so that "only the loopback device is created"; the flag is --network none.
The Local Server Security guide's advice is to deny network where none is needed and, for servers that do need egress, to know their short list of destinations and route them through an outbound-filtering firewall or a proxy with a domain allowlist. A server that wraps one API has a predictable set of hosts; traffic elsewhere is worth a look.
The guide adds a second network point that is easy to miss: local components that listen on a port (bridges to remote servers, development tools, locally hosted HTTP servers) are reachable by other local processes and, through your browser, by websites. "Binding to 127.0.0.1 is not an authentication boundary", so such components need real authentication and origin checks, and prompt updates when advisories land.
How do I check what a local server exposes, before and after install?
Checking a local MCP server has two moments: the install command, which a one-click flow must show you in full, and the tool list, which the server sends at runtime and can change after you approved it. Neither moment is covered by pinning alone.
SEP-1024, a Final Standards Track proposal created on 22 July 2025, requires clients that support one-click local server configuration to display "The exact command that will be executed, without truncation", with all arguments and a warning, and to require explicit approval. Read that dialog the way you would read a shell command someone sent you.
After install, read the tool list. The official guide says tool names and descriptions are "instructions your model reads", that a server "can quietly change them after you approved it", and that "a one-time consent dialog and package pinning do not cover this surface". The earlier post on reading tool schemas for poisoning shows how to dump a tool list and what to look for in descriptions, enums and defaults.
mcp.tc can help with the "after" part within clear limits. Every 3 hours it reads the tool lists it can reach without signing in and records added and removed tools, changed descriptions, schemas and annotations on each listing's History tab, after two reads agree. On 22 November 2026, 589 listings had a watched tool list, with history kept since 6 October 2026. For local servers, that includes only servers whose tools come from an MCP bundle manifest in their GitHub repository; mcp.tc never runs a local server, so a local listing without a manifest has a History tab of version numbers and owner edits only. It cannot see tools shown only after sign-in or only to some clients, a change undone between two checks can be missed, and none of it is a security review. The guide's own caveat covers directories like this one: curated catalogs "describe their own vetting as best-effort: curation reduces risk, it does not take on accountability for what you run."
What you can do next on mcp.tc
Filter the directory by servers that run locally, then open a listing to see its package, whether it needs sign-in, and setup steps for Claude Code, Claude Desktop, Cursor, VS Code, Codex, Gemini CLI and a generic JSON config, each using the server's own package so the client launches it directly. Replace the launcher in those steps with the docker run form above if you want the container boundary.
Open the listing's History tab and press Follow to get an email when mcp.tc's checks see a new npm or PyPI version, or when the owner edits the listing; Recent changes shows the newest changes across the directory. From a terminal, npx mcp-tc add from the mcp-tc command-line tool shows the command or config change before it applies anything and asks first, and API keys stay on your computer. If a local server you rely on is not listed yet, suggest it at mcp.tc/submit.
FAQ
Is a local stdio MCP server safer than a remote one?
Not by default. The MCP stdio transport launches the server as a subprocess of your user account, so it reads your files and environment and opens any outbound connection, with no sandbox from the protocol. A remote Streamable HTTP server runs no code on your machine and uses the protocol's authorization flow instead. Local servers are the right choice when a job needs your working tree, a local tool or hardware; then isolation, pinning and scoped credentials are yours to add.
Does pinning a version with npx -y protect me from a compromised dependency?
Only partly. npx -y example-server@1.4.2 fixes the top-level package, but the MCP project's Local Server Security guide notes that transitive dependencies are typically resolved fresh at install time, which is where a compromised dependency arrives. Pinning a container image by digest (image@sha256:...) freezes the entire dependency tree. Either way, a pin also keeps you on an old release when a fix ships, so watch for new versions and update deliberately.
Do MCP roots restrict which directories a server can access?
No. The 2026-07-28 specification describes roots as "informational guidance rather than an access-control mechanism" and says the protocol does not enforce that servers stay within them. Roots are also deprecated as of that revision (SEP-2577), with a migration to passing directories through tool parameters, resource URIs or server configuration. Real enforcement comes from the operating system: a container or sandbox where the allowed directory is the only filesystem the process can see, mounted read-only when possible.
Why does my containerized MCP server not start from the client?
Three causes cover most cases. The docker run command needs -i so stdin stays open for the stdio transport. Every path in the client config must be absolute, including the host side of the -v mount. And the server must write nothing to stdout except MCP messages; the stdio binding says a server "MUST NOT write anything to its stdout that is not a valid MCP message", so an image that prints a banner on start breaks the connection. Client logs, which capture the server's stderr, usually name the cause.
Can mcp.tc tell me whether a local MCP server is safe?
No, and it does not claim to. mcp.tc lists what a server does, which package it comes from, whether it needs sign-in and how to set it up in each client, and it records new npm or PyPI versions on the History tab so you notice updates. It never runs local servers, so it watches a local server's tool list only when that list comes from an MCP bundle manifest in the server's GitHub repository. The verified checkmark says who runs a server, not that it is safe.
Is a Docker container with default settings enough?
Docker's docs say containers are "unprivileged" by default and keep a default list of capabilities, but the default user is root and the network is connected. Adding --cap-drop ALL, --read-only, a non-root --user, --network none where no network is needed and a single read-only mount removes most of what common attacks rely on. The MCP project's guide still calls a container "not an impenetrable boundary"; seccomp, AppArmor or SELinux, a separate user account or a microVM go further.
Sources
- modelcontextprotocol.io/docs/2026-07-28/tutorials/security/local-server-security
- modelcontextprotocol.io/specification/2026-07-28/basic/transports/stdio
- modelcontextprotocol.io/specification/2026-07-28/client/roots
- modelcontextprotocol.io/specification/2026-07-28/changelog
- modelcontextprotocol.io/seps/1024-mcp-client-security-requirements-for-local-server-
- modelcontextprotocol.io/docs/2026-07-28/develop/connect-local-servers
- docs.docker.com/reference/cli/docker/container/run/
- docs.docker.com/engine/containers/run/
- docs.docker.com/engine/storage/bind-mounts/
- docs.docker.com/engine/network/drivers/none/
- docs.docker.com/reference/cli/docker/image/pull/
- docs.npmjs.com/cli/v11/commands/npx
- docs.npmjs.com/cli/v11/commands/npm-view
- docs.astral.sh/uv/guides/tools/
- code.claude.com/docs/en/mcp
- code.visualstudio.com/docs/agents/reference/mcp-configuration