Running MCP servers safely

This is an independent reference page. It is not affiliated with the Model Context Protocol project or any AI company.

Written against specification revision 2026-07-28 (current). Facts checked November 2026.

Authorization: who must do what

The authorization specification is optional and applies to HTTP transports. A stdio server should not use it and should take credentials from its environment. When it is used, the MCP server is an OAuth 2.1 resource server, the MCP client is an OAuth 2.1 client, and the authorization server is a separate role that may be co-hosted.

Discovery chain

  1. The server must publish Protected Resource Metadata (RFC 9728) with at least one entry in authorization_servers. It points clients there with a resource_metadata parameter on the 401 challenge, or by serving the well-known URI /.well-known/oauth-protected-resource. Clients must support both.
  2. The authorization server must publish either OAuth Authorization Server Metadata (RFC 8414) or OpenID Connect Discovery. Clients must support both, and the issuer in the document must match.
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource",
                         scope="files:read"

Client registration

Three mechanisms exist (client registration). Clients that support all of them should prefer pre-registered credentials, then a Client ID Metadata Document (the client_id is an HTTPS URL that serves a JSON document with client_id, client_name and redirect_uris) when the authorization server advertises client_id_metadata_document_supported, then Dynamic Client Registration (RFC 7591). Dynamic registration is deprecated as of 2026-07-28.

Rules for clients

Rules for servers

Scopes and least privilege

The official security best practices describe a progressive model: start with a minimal scope set covering low-risk discovery and read operations, then raise privilege only when a privileged operation is first attempted. The mechanism is a 403 challenge that names what is missing:

HTTP/1.1 403 Forbidden
WWW-Authenticate: Bearer error="insufficient_scope",
                         scope="files:write",
                         resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource"

The client then re-authorizes with the union of the scopes it already had and the new ones. Mistakes that page names: publishing every scope in scopes_supported, wildcard scopes such as * or all, and treating a scope claim in the token as sufficient without server-side authorization logic.

Attack classes the project documents

Confused deputy

Applies to an MCP server that proxies to a third-party API. Conditions: the proxy uses one static client ID with the third-party authorization server, lets MCP clients register dynamically, and the third party remembers consent in a cookie. An attacker registers a client with their own redirect URI and sends the victim a crafted link. The third party sees the consent cookie, skips its consent screen, and the authorization code lands with the attacker. Required mitigation: the proxy must obtain its own per-client consent before forwarding. It keeps a registry of approved client_id values per user, shows the client name, scopes and redirect_uri on its consent page, and matches redirect URIs by exact string.

Token passthrough

The server accepts a token that was not issued to it and relays it downstream. This bypasses controls that depend on audience and breaks the audit trail, since the downstream log shows the wrong identity. The rule is absolute: servers must not accept tokens that were not explicitly issued for them.

State handle hijacking (formerly session hijacking)

Revision 2026-07-28 has no protocol-level sessions, so the session hijacking entry of earlier guidance has become state handle hijacking. A server that needs state across calls mints a handle (a cart ID, a workflow ID) and receives it back as an ordinary tool argument. If the server does not check that the handle belongs to the caller, anyone who obtains or guesses it gets the other user's state. Servers must not treat possession of a handle as authentication. They should generate handles with a secure random generator and bind them to the authenticated user, for example by keying state as <user_id>:<handle> with the user ID taken from the verified token. The 2025-11-25 version of the page still covers legacy session IDs.

Others on the same page

Server-side request forgery through OAuth metadata URLs, local server compromise through one-click install commands (the client must show the exact command untruncated and require explicit approval), and mix-up attacks.

Prompt injection and tool poisoning

The local server security guide states the problem directly: tool names and descriptions are instructions the model reads. A server can hide directives in them that steer the agent, including how it uses other servers' tools, without the poisoned tool ever being invoked. The guide calls this tool poisoning, or tool shadowing when it targets another server's tools. Definitions can also change after approval (a rug pull), so a one-time consent dialog and package pinning do not cover it. Prompt injection in untrusted content can likewise steer an honest server into overreach.

Every configured server shares the same model context, so each install extends the surface the others are exposed to. The stdio transport is not a sandbox. Containment (a container, sandbox or VM with as few privileges as possible) decides what a bad trust decision costs.

Tool design

The tools specification requires servers to validate all tool inputs, implement access controls, rate limit invocations and sanitize outputs. It says there should always be a human in the loop able to deny a tool invocation, and that clients should show tool inputs to the user before calling. The tool list must not vary per connection, though it may vary by the authorization presented.

Annotations are hints

FieldDefaultMeaning
readOnlyHintfalseTool does not modify its environment
destructiveHinttrueTool may perform destructive updates. Meaningful only when readOnlyHint is false
idempotentHintfalseRepeating the call with the same arguments has no additional effect
openWorldHinttrueTool interacts with external entities

Note the defaults: an unannotated tool is assumed to be destructive and open-world. The schema says these properties are not guaranteed to describe the tool faithfully, and that clients should never make tool use decisions based on annotations received from untrusted servers. Annotations inform a confirmation prompt. They are not an access control.

HTTP exposure

For Streamable HTTP, servers must validate the Origin header on incoming connections to prevent DNS rebinding, answering 403 when it is invalid. A server running locally should bind only to localhost (127.0.0.1), not all interfaces, and should implement authentication.

The official registry

The MCP Registry at registry.modelcontextprotocol.io is a metadata service for publicly accessible servers, in preview at the time of checking. It stores a server.json per version that points at a package (npm, PyPI, Docker Hub and others) or a remote URL. It hosts no code. Source: github.com/modelcontextprotocol/registry.

Testing with the Inspector

The MCP Inspector (repository) ships as one npm package with a web UI, a CLI and a terminal UI.

npx @modelcontextprotocol/inspector node path/to/server/index.js

npx @modelcontextprotocol/inspector --cli node path/to/server/index.js --method tools/list

npx @modelcontextprotocol/inspector --cli https://api.example.com/mcp --transport http \
  --method tools/call --tool-name get_weather --tool-arg city=Boston

It defaults to the legacy protocol era (a plain initialize). Pass --protocol-era modern to pin 2026-07-28, or auto to probe server/discover first. Per its security page, the web backend can spawn processes, binds 127.0.0.1 by default and guards its API with a per-launch token, and on a machine with no OS keychain it stores secrets in ~/.mcp-inspector/secrets.json, unencrypted unless a key is supplied.

Official SDKs

From the SDK page. SDKs adopt new revisions on their own schedules, so confirm 2026-07-28 support in the SDK's own documentation.

TierRepositories under github.com/modelcontextprotocol
1typescript-sdk, python-sdk, csharp-sdk, go-sdk, rust-sdk, ruby-sdk
2java-sdk
3swift-sdk, php-sdk, kotlin-sdk