Skip to main content

How to secure an MCP server in a SaaS product

Secure SaaS MCP servers with caller authentication, per-tool authorization, input validation, tenant isolation, audit logs and current-protocol guidance.

In this guide

How do you secure an MCP server?

Secure a Model Context Protocol (MCP) server as a privileged API boundary. Authenticate the calling identity, authorize each tool and resource for the current user and tenant, validate every argument, constrain downstream effects, and record a privacy-conscious audit trail. MCP standardizes how clients discover and invoke capabilities; it does not decide whether a caller should be allowed to read a particular customer's record or approve a consequential action. The final 2026-07-28 protocol removed protocol-level stateful sessions, so application authorization must not depend on a legacy session identifier.

Inventory tools, resources and downstream effects

List each exposed tool, resource and prompt; identify its data classification, tenant scope, downstream API, side effect and owner. Describe what a tool can actually do in plain language, including indirect effects such as sending email, exporting a report or changing a billing setting. Remove unused capabilities and make read-only operations distinct from writes. A name or schema is not a security review.

Put authentication and authorization in trusted server code

Validate the OAuth access token for the intended resource, issuer, audience, expiry and required scopes. Bind the authenticated principal and tenant to server-side request context; never accept a model-generated tenant ID, user ID or permission claim as proof. Apply object-level authorization again when the tool accesses a record, because permission to invoke a tool does not imply permission to access every object it can address.

Keep privileged approvals outside the model

Require an explicit, informed confirmation for high-impact operations such as external sharing, payments, account deletion or permission changes. Show the user the exact target and effect before confirmation, then re-check authorization and policy at execution time. A prompt saying “ask first” is not an approval control, and an approval for one action should not silently authorize a later or broader action.

MCP server capability and authorization review
Tool/resourceData and tenant scopeRead/write effectRequired identity/scopeApproval and audit

How should an MCP server validate requests and isolate tenants?

Treat tool arguments and returned content as untrusted

Validate types, lengths, enumerated values, identifiers and cross-field rules against a strict schema, then apply business validation in the underlying service. Use parameterized database operations and safe output handling. Tool descriptions help a model choose a capability; they do not sanitize arguments or make returned text trustworthy. Reject malformed or over-sized requests rather than trying to repair them silently.

Carry tenant context from verified identity to every data operation

Derive tenant scope from the authenticated principal or a trusted server-side mapping. Enforce it in the service and data layer, including searches, pagination, caches, background work and error paths. Test that a guessed identifier, stale reference, batch request or resource URI cannot cross tenant boundaries. Re-check authorization on each call; do not treat prior discovery or a previous tool result as continuing permission.

Constrain outbound connections and server privileges

Allowlist downstream hosts, methods and operations; block arbitrary URL fetches and internal metadata addresses. Use a dedicated service identity with only the permissions required by each capability, store credentials in a managed secret system, and rotate or revoke them through a tested process. Apply request, response, concurrency and time limits so a valid-looking tool call cannot exhaust the server or a downstream dependency.

How do you operate and test a secure MCP server?

Use current protocol authorization rules and safe deployment defaults

Follow the current MCP authorization specification for the transport and client you support, including issuer and resource validation. Do not copy older examples that rely on a protocol-level stateful session identifier: the 2026-07-28 final specification removed that mechanism. Keep any application-level actor, tenant and correlation identifiers separate from authentication credentials, and never use correlation data as authorization evidence.

Log decisions without copying customer content into logs

Record authenticated actor and tenant references, tool name, authorization outcome, policy version, request correlation ID, time, result status and downstream trace IDs. Minimize or redact arguments and outputs that may contain personal or confidential data; restrict log access and set retention. Ensure a security reviewer can reconstruct who initiated an action and what happened without making a broad transcript archive.

Test negative cases and revoke access quickly

Exercise expired, wrong-audience and wrong-issuer tokens; missing scopes; cross-tenant IDs; malformed arguments; replayed requests; hostile resource text; timeout and partial failure paths; and denied high-impact actions. Verify revocation and credential rotation, then test that incidents can disable a tool or client without taking unrelated service features offline. Re-run these checks when schemas, tools, providers or protocol versions change.

MCP server security FAQs