Security and Authentication
7.1 MCP Security Model
MCP’s security responsibilities are distributed across different layers:| Layer | Responsible Party | Content |
|---|---|---|
| Transport Security | Transport layer | HTTPS encryption, certificate verification |
| Identity Authentication | OAuth 2.1 + Server | Verify caller identity |
| Permission Control | Server | Control tool access for different users |
| Data Privacy | Server + Host | Prevent sensitive data leakage to AI models |
| Tool Safety | Host | Require user confirmation for high-risk tool calls |
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
| RFC | Name | Role in MCP |
|---|---|---|
| draft-ietf-oauth-v2-1-13 | OAuth 2.1 | Core authorization framework |
| RFC 7636 (PKCE) | Proof Key for Code Exchange | Prevents authorization code interception attacks (MCP mandates the S256 method) |
| RFC 8414 | Authorization Server Metadata | Client auto-discovers authorization server endpoints and capabilities |
| RFC 7591 | Dynamic Client Registration | Client auto-registers on first connection |
| RFC 9728 | Protected Resource Metadata | Server declares its authentication requirements and associated authorization servers |
| RFC 8707 | Resource Indicators | Client specifies the target resource when requesting tokens |
Complete Authentication Flow
PKCE (Proof Key for Code Exchange)
MCP mandates PKCE and requires theS256 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:| Permission Level | Description | Example Tools |
|---|---|---|
| Public | No authentication required | search_products, get_categories |
| Logged in | Requires a valid access_token | get_order, list_orders |
| Owner | Can only operate on own data | create_return, update_profile |
| Admin | Requires admin privileges | update_inventory, manage_promotions |
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.| Safe to Return | Should Not Return |
|---|---|
| Product names, prices, inventory | User passwords, payment credentials |
| Order status, shipping info | Full credit card numbers |
| Public company information | Internal cost prices, profit margins |
| Redacted user information | Full government ID numbers |
Resource Annotations for Privacy Control
Use theaudience 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