Audit an MCP Server Before Giving It Files, Tokens, or Network Access

Safety boundary: Inspect untrusted integrations without executing their setup instructions. Use synthetic files, an isolated environment, and an owned test tenant before introducing credentials. Do not point denial tests at production systems, real cloud metadata services, or another organization's endpoints.

Quick Answer

Treat an MCP server as executable software or a remote service with delegated authority, not as a harmless plugin description. Inspect its exact artifact, startup command, operating-system identity, tools, file access, network destinations, and token scopes before enabling it. Start with fake data and enforced runtime restrictions, then verify both permitted actions and denied actions. MCP standardizes communication; it does not universally sandbox servers, constrain their filesystem access, or make returned documents trustworthy.

Audit the permissions behind an MCP tool call

The protocol connects tools to a client; it does not automatically sandbox the server process or make returned content trustworthy.

1. Identify

Verify the exact package, maintainer, version and launch command.

2. Constrain

Limit files, credentials, process identity and network destinations.

3. Challenge

Use synthetic data to test forbidden reads and unauthorized actions.

4. Revoke

Confirm you can stop the process and invalidate its credentials.

A local server asks for your whole home directory

Start with a dedicated test directory and a low-privilege process identity. Inspect mounted paths and environment variables. A friendly tool description is not an enforced filesystem boundary.

A remote server requests a broad token

Check the exact audience, scopes, authorization flow and credential storage. Do not pass a token intended for a different service. Prefer a dedicated revocable identity and the smallest supported scope.

A document tells the agent to change its instructions

Treat the document and tool output as untrusted data. Authorization and destination restrictions must still hold when the content is persuasive or malicious. Human approval is useful only when the proposed action and its effects are understandable.

Draw the Trust Boundaries Before Reading the Tool List

Model Context Protocol (MCP) connects an AI application's client to a server exposing tools and data. The host is the application coordinating the model, conversation, approvals, and clients. The server might be a local subprocess reading files or a remote service accessing a business account.

Write down this chain for the proposed integration:

Boundary Question to answer
User to host Which user or workspace is granting permission, and who can change it?
Host to local process or HTTP server What executable or endpoint receives requests?
Server to operating system Which files, processes, sockets, and identities can it use?
Server to downstream services Which accounts, tokens, destinations, and operations are available?
Tool result to model and other tools Where can returned data go next?

For example, a documentation search server might need one read-only folder and no network. A ticket connector might need one project's read scope and access to its API. Neither task justifies your entire home directory, a cloud administrator token, or unrestricted execution.

Keep the task narrow enough that an unexplained permission is a reason to stop. "It might need this later" is not an access requirement.

This guide is documentation-backed. No candidate server, OAuth tenant, or runtime denial was tested for this article. The examples below describe inspections and expected states, not observed output.

Verify What You Would Actually Execute

Identify the publisher, repository, package registry entry, release, dependency lockfile, and release security policy. Compare the advertised installation command with the artifact it actually selects. A plausible repository name does not establish that a similarly named package belongs to that publisher.

Record an exact package version or image digest and how you obtained it. A digest identifies content; it is not proof that the publisher is legitimate or the content is safe. Check available signatures and attestations against the publisher's documented trust process, not merely whether a verification command prints a reassuring label.

Read startup scripts, install hooks, entry points, dependency declarations, and lockfile sources before installation. A launcher such as npx or uvx may retrieve and execute code; it is not a neutral way to preview an unknown server. Importing a module or opening its project in an environment that automatically runs tasks can also execute code.

For an already obtained source copy in a disposable review environment, these are unperformed inspection examples. They require jq, rg, and the expected files; do not install or run the package to make them work:

jq '{name, version, bin, scripts, dependencies, optionalDependencies}' package.json
jq '{lockfileVersion, packageCount: (.packages | length)}' package-lock.json
rg -n 'child_process|exec\(|spawn\(|subprocess|eval\(|fetch\(|https?://' src
sha256sum package.json package-lock.json

Expect manifest fields, a lockfile summary, source matches, and file hashes, not a security verdict. Missing files may mean another packaging format; inspect its equivalent metadata rather than generating a new lockfile and pretending it represents the shipped artifact. Keep potentially sensitive repository URLs and output private.

Search matches are leads. A normal HTTP client can be legitimate; a malicious implementation can avoid these strings entirely. Review the called code, generated code, transitive dependencies, and artifact build path. Manifest hashes do not identify every installed file or transitive dependency.

Check the actual project's security policy. The official reference-server security policy distinguishes maintained reference servers, archived projects, and third-party servers. That scope is not a guarantee covering everything listed in a registry. Report suspected vulnerabilities privately through the responsible maintainer's process.

Local stdio and Remote HTTP Need Different Questions

With stdio transport, the client launches a subprocess and communicates through its standard input and output. The launch identity, inherited environment, working directory, executable search path, and operating-system permissions matter immediately. No OAuth consent screen is required to turn an overprivileged subprocess into a serious risk.

Use an absolute, reviewed executable path where the client supports it. Examine wrapper scripts and environment inheritance. Do not pass the host's full environment simply because the server needs one credential. The process can access more than the tools shown in its advertised schema if its operating-system identity permits it.

With HTTP, record the endpoint, operator, TLS identity, authentication, tenant handling, retention terms, and downstream data destinations. The server runs outside the local client's process boundary. A local sandbox around the client does not constrain that remote server's backend.

For a local HTTP listener, verify the bound interfaces and allowed browser origins. The Streamable HTTP binding requires validation of a supplied Origin and rejection of an invalid origin with HTTP 403; it recommends localhost binding for local operation and proper authentication. Origin checking is a browser-related defense, not user authentication. A missing Origin is not proof of a trusted client.

Match tests to the implemented protocol revision. In the cited 2026-07-28 revision, Streamable HTTP removes protocol-level sessions and the old GET stream endpoint. Earlier revisions use different lifecycle behavior. Do not label a modern implementation broken because an older tutorial expects a session header, or assume a legacy deployment gained new protections merely by changing its URL. TechGeeks' MCP migration guide covers compatibility separately.

Separate MCP Authorization From Downstream Tokens

For a protected HTTP server, identify three roles: the MCP client, the MCP resource server receiving requests, and the authorization server issuing the access token. A downstream service such as a ticket or repository API is another resource with its own authorization boundary.

The cited MCP authorization specification defines HTTP authorization behavior, including resource indicators and validation that tokens are intended for the receiving MCP server. It references OAuth 2.1 as an IETF draft; "OAuth support" alone does not demonstrate implementation of every relevant security requirement.

Ask for evidence of issuer and audience validation, expiry checking, restricted scopes, redirect handling, and Proof Key for Code Exchange (PKCE). PKCE ties an authorization-code exchange to the client that initiated it. Review consent and refresh-token storage as well as the initial login screen.

Avoid a design that accepts a token intended for another API as if it were authorization to the MCP server, then forwards it unchanged downstream. The MCP security best practices explicitly address this token-passthrough anti-pattern. A proxy must preserve the distinction between who may use the MCP service and what downstream authority the user delegated.

Prefer a dedicated test account or service identity with the smallest useful project, repository, or tenant scope. Record whether "read" permits bulk export or exposure of confidential fields. A read-only token may still be powerful enough to disclose an entire customer database.

Never put real tokens in example commands, URL query parameters, screenshots, support messages, or verbose HTTP traces. Review where the host, server, proxy, and identity provider log request headers and tool arguments. A secret manager improves distribution and storage; it does not stop an authorized process misusing a secret it receives.

Enforce Filesystem and Network Limits Outside the Prompt

A folder picker is not necessarily filesystem enforcement. The cited roots specification says roots are informational guidance, not an access-control mechanism; the feature is deprecated in that revision. Enforce access with the server's validated policy and the operating system, container runtime, or a separate virtual machine.

For a first local trial, choose a dedicated unprivileged identity and a synthetic folder. Do not mount the home directory, credential stores, SSH agent, browser profile, cloud configuration, host container socket, or a production repository containing secrets. Mounting a folder read-only prevents modification through that mount, not reading and returning its contents.

The following unperformed Linux-container example is only for an already reviewed, locally available, digest-pinned image whose documented default entry point supports stdio, a nonroot user, and /workspace. It is not an install command or a universal MCP client configuration. Review the image's built-in environment, declared volumes, and startup behavior too.

Use a local Docker Engine in the disposable review environment, not a remote or production Docker context. Bind mounts refer to the daemon host, not necessarily the machine running the CLI. Reject unexpected image-declared writable volumes: --read-only constrains the root filesystem, not every separately mounted volume.

First create fake data in a fresh disposable working directory:

install -d -m 755 fixtures/allowed
printf '%s\n' 'MCP_AUDIT_ALLOWED_FAKE_DATA' > fixtures/allowed/readme.txt
chmod 644 fixtures/allowed/readme.txt

Set MCP_AUDIT_IMAGE to that reviewed local image reference, including its actual @sha256: digest. Do not substitute an invented digest. Then launch:

: "${MCP_AUDIT_IMAGE:?Set a reviewed local image@sha256:digest first}"
case "$MCP_AUDIT_IMAGE" in
  *@sha256:*) ;;
  *) printf '%s\n' 'Refusing an image without a digest' >&2; exit 1 ;;
esac
docker run --rm -i --pull=never --name mcp-audit-candidate \
  --user 65532:65532 \
  --network none \
  --read-only \
  --cap-drop ALL \
  --security-opt no-new-privileges=true \
  --pids-limit 64 --memory 256m --cpus 1 \
  --tmpfs /tmp:rw,noexec,nosuid,size=16m,mode=1777 \
  --mount "type=bind,src=$PWD/fixtures/allowed,dst=/workspace,readonly" \
  "$MCP_AUDIT_IMAGE"

The Docker CLI reference documents these runtime controls. This pattern provides no ordinary external network, a read-only root filesystem and fixture mount, reduced privileges, and bounded resources; /tmp remains writable. It deliberately passes no host credentials or listening ports. The -i preserves stdin; no pseudo-terminal is allocated for protocol traffic.

Configure the reviewed client's stdio launcher with equivalent executable arguments using that client's documented format. A server waiting for protocol input may appear idle; an idle terminal is not proof of a successful MCP exchange. If startup fails because the image expects root, writable state, network, or another entry point, stop and resolve the requirement. Do not remove restrictions until the failure disappears and call that an audit.

Containers share a kernel and are not a universal boundary against hostile code. For a genuinely untrusted candidate, use a disposable virtual machine with no sensitive host integration, and consider rejecting it rather than executing it.

Require Deny Tests With a Positive Baseline

Run tests through the reviewed client against synthetic data. Capture the actual tool name, arguments, identity, runtime settings, timestamp, result, and relevant enforcement log. Do not copy JSON-RPC messages from a different protocol revision and interpret a parse error as permission enforcement.

Test Expected state What a failure means
Read /workspace/readme.txt Returns only the fake allowed marker Fix compatibility or ordinary read access before evaluating denials
Create /workspace/should-not-exist.txt through any available write tool Denied; host fixture stays unchanged Read-only scope is not enforced as expected
Read a synthetic path outside the approved scope Denied or absent, without disclosing content Any returned outside marker blocks admission
Follow an allowed-folder symlink toward an unapproved synthetic location No unauthorized content Review canonicalization and alternate path handling
Attempt one owned network destination with networking disabled Fails from the server process boundary Unexpected success requires identifying another network or proxy path

Distinguish two filesystem questions. An unmounted file returning "not found" demonstrates that the particular path is absent in the container; it does not prove the server's own path allowlist is correct. Testing application-level traversal or symlink policy requires an isolated fixture arrangement where a synthetic outside file would otherwise be readable. Keep that test in the disposable environment, never against real host secrets.

For network tests, prove the owned destination is reachable from a separate approved baseline, then verify denial from the exact server boundary. If the server has no fetch-like operation, do not add a shell-execution tool to manufacture one. Use a trusted diagnostic process in the same runtime/network policy and identify that narrower test honestly.

An online integration needs more than a hostname list. Define required API hosts, ports, DNS resolution, proxies, and redirect handling. Block unauthorized internal networks and cloud metadata destinations by policy; inspect configuration rather than probing real metadata credentials. Test redirects only between owned inert endpoints. A proxy that accepts any destination supplied in a URL is not an effective egress restriction.

Server-side request forgery (SSRF) can occur in URL-fetch tools and authorization discovery. Validate destination resolution and every redirect at the relevant component, with IPv4 and IPv6 coverage. Do not assume a denied ordinary fetch proves that OAuth discovery, logging exporters, subprocesses, or another tool use the same path.

Check Protected HTTP and Authorization Without Leaking Tokens

Use a test deployment and the server's documented request for a harmless operation. First prove that the valid, limited test identity can perform it. Repeat without authorization: the protected operation must not return its data. A 404 on the wrong route or 400 for malformed protocol input is inconclusive.

For a local HTTP deployment, repeat an otherwise valid benign request with a deliberately disallowed Origin such as https://untrusted.example. Expect rejection under the documented Origin policy. Do not attach a production token to the test or publish a trace containing authorization headers. An early authentication rejection may be safe, but it does not independently prove Origin enforcement.

Wrong-audience, expired-token, revoked-token, and cross-user access tests belong in an owned test tenant using its supported tooling. Never paste one real service's token into another service to "see what happens." Test that a valid user cannot access another synthetic user's record, and that denial is enforced by the resource service rather than merely hidden in the client.

Keep permissions after restart and reconnection in scope. A client that remembers blanket approval, a server that restores a broader configuration, or a refresh token that survives account removal can invalidate the first trial's apparent boundary.

Treat Tool Results and Documents as Untrusted Input

Prompt injection happens when untrusted content attempts to redirect the model's behavior. It can arrive in a document, tool description, search snippet, ticket comment, or server response. OWASP's prompt-injection guidance supports layered controls rather than treating a stronger instruction as a complete defense.

Review every exposed tool schema and description. Compare claimed read-only or nondestructive behavior with implementation and downstream permissions. Parameters that accept arbitrary paths, URLs, commands, SQL, or broad search scopes deserve specific review. A schema validates shape; it does not by itself authorize the requested action.

For a harmless synthetic test, put a sentence in a fixture document telling the model to ignore the user's task and request an unrelated write action. The expected outcome is no unapproved write or new authority. Record whether the host asks for approval, rejects the action, or lacks the authority entirely. A refusal once does not establish immunity to prompt injection.

Consider composition: a read-only server can expose sensitive text that another tool sends elsewhere. Removing network from the server does not stop stdout from reaching the host, the model provider, conversation storage, or a different enabled connector. Review those data paths and retention terms too. TechGeeks' self-hosted AI egress audit expands that broader privacy question.

Decide, Revoke, and Review Changes

Admit the server only when its purpose, publisher, artifact, privileges, data destinations, and revocation path are explainable. Restrict it when a useful narrow deployment exists. Reject it when the workflow depends on unexplained administrator authority, unrestricted host access, token passthrough, or disabling controls to make it run.

Save the approved artifact identity, startup configuration, tool schema, permission decision, and owner. Re-review changes to dependencies, tool descriptions, scopes, runtime mounts, endpoints, and auto-update behavior. Pinning controls change; it must not become a reason to ignore security fixes.

For recovery, disable the integration and its automatic restart, then stop the candidate process. In the container example, a separate terminal can run this unperformed cleanup command after confirming the name identifies only your trial:

docker stop mcp-audit-candidate

The --rm launch removes the stopped container, not the host fixture directory. An absent container is not an instruction to stop unrelated processes. Preserve needed evidence before removing the disposable environment.

Revoke the MCP grant and downstream credentials through their issuers, invalidate refresh tokens and active sessions where supported, and verify a new request fails. If real secrets were exposed, rotate them and assess what was accessed; removing the configuration entry cannot retract data already returned. Restore a known-good client configuration only after confirming it does not re-enable the rejected server.

For workflows with write authority, use explicit action approval and recovery design such as TechGeeks' AgenticOps approval and rollback guide. The admission decision should rest on enforceable limits and observable behavior, not the presence of an MCP logo or a successful connection.

References

Leave a Reply

Your email address will not be published. Required fields are marked *