Skip to main content

Security and Authentication

7.1 MCP Security Model

MCP’s security responsibilities are distributed across different layers:

7.2 OAuth 2.1 Authentication

The MCP specification defines the authentication mechanism for remote Servers based on OAuth 2.1 (draft-ietf-oauth-v2-1-13). This is not a new authentication scheme invented by MCP; it relies entirely on existing OAuth standards and related RFC specifications.

Referenced RFC Standards

Complete Authentication Flow

PKCE (Proof Key for Code Exchange)

MCP mandates PKCE and requires the S256 method (plain is not allowed). PKCE prevents authorization codes from being abused if intercepted by a man-in-the-middle:

Token Type

MCP uses Bearer Tokens. The access_token is passed in the HTTP request header:

7.3 Server-Side Authentication Implementation

7.4 Permission Control

Different tools require different permission levels:

Tool-Level Permission Matrix

It is recommended to define clear permission requirements for each tool:

7.5 Data Privacy

Principle: Data returned by the Server will be processed by the AI model. Do not include sensitive information in tool responses that should not be “seen” by the AI.

Resource Annotations for Privacy Control

Use the audience field in Annotations to control the target audience of a resource:
audience: ["assistant"] indicates the resource is intended for AI model processing only and should not be directly displayed to users. The Host can use this to decide whether to hide the resource in the UI.

7.6 Transport Security

Remote Servers (Streamable HTTP)

  • HTTPS required: Production environments must use TLS encryption
  • Certificate verification: Clients should verify the Server’s TLS certificate
  • CORS: If the Client is a browser application, the Server needs appropriate CORS policies

Local Servers (stdio)

stdio local Servers are inherently secure (no network exposure), but still require attention to:
  • Do not hardcode database passwords in code; use environment variables
  • Limit filesystem access scope (in conjunction with the Roots mechanism)
  • Do not log sensitive data
  • Run the Server process with minimal privileges

7.7 Security Checklist

When developing an MCP Server, use the following checklist to ensure security:
  • Does the remote Server use HTTPS
  • Is OAuth 2.1 authentication implemented (including PKCE S256)
  • Do sensitive tools check user permissions
  • Is returned data properly redacted
  • Are environment variables used for storing secrets
  • Are logs free of sensitive information
  • Are input parameters validated and sanitized
  • Is request rate limiting implemented

Next Chapter: Testing and Debugging — MCP Inspector usage guide