TL;DR - Security Essentials
Secure your MCP integrations with these core principles:
π 2025: MCP security now includes OAuth 2.1 with PKCE, RFC 9700 best practices, and Zero Trust architecture alignment. For an introduction to MCP, see the MCP Introduction guide.
The Golden Rules:
- π Least Privilege: Grant minimal required permissions
- π Scoped Tokens: Use service-specific API keys
- π Secure Storage: Never commit credentials
- ποΈ Audit Logs: Monitor access regularly
- π Rotation: Change keys periodically
Quick Security Checklist:
β Use read-only access when possible
β Create dedicated API keys for MCP
β Store credentials in environment variables
β Add config files to .gitignore
β Enable audit logging on services
β Rotate credentials quarterly
β Review access scope monthly
Security Model Overview
Understanding how MCP security works:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Security Layers β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β AI Host βββββΆβ MCP Server βββββΆβ Service β β
β β(Claude/etc) β β β β(GitHub/AWS) β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β β β
β βΌ βΌ βΌ β
β User approves Scoped Service-side β
β each server access permissions β
β β
β Layer 1: User Layer 2: Token Layer 3: Service β
β Control Permissions Access Control β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Three Layers of Protection
| Layer | What It Protects | You Control |
|---|---|---|
| 1. User Control | Which MCP servers run | Config file |
| 2. Token Permissions | What each server can do | API token scopes |
| 3. Service Access | What resources are accessible | Service-side policies |
2025 Security Enhancements
| Feature | Description |
|---|---|
| OAuth 2.1 + PKCE | Authorization Code flow with Proof Key |
| RFC 9700 | IETF best practices for OAuth security |
| Resource Indicators | Explicit target resource specification |
| No Token Passthrough | MCP servers donβt pass tokens upstream |
| Zero Trust | Behavioral analytics and pattern detection |
Credential Management
Never Do This
// β BAD: Credentials in version control
{
"mcpServers": {
"github": {
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_real_token_12345"
}
}
}
}
Do This Instead
Option 1: Environment Variables
// β
GOOD: Reference environment variables
{
"mcpServers": {
"github": {
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
}
}
}
}
Option 2: Separate Config (not in version control)
Keep claude_desktop_config.json out of your repo by:
- Adding to
.gitignore - Using system-level paths only
- Never copying to project directories
Option 3: Secret Manager (Enterprise)
# Use a secret manager to inject credentials
export GITHUB_TOKEN=$(aws secretsmanager get-secret-value \
--secret-id mcp/github --query SecretString --output text)
Credential Storage Locations
| Platform | Config Location | Secure? |
|---|---|---|
| macOS | ~/Library/Application Support/Claude/... | β User-only |
| Windows | %APPDATA%/Claude/... | β User-only |
| Linux | ~/.config/Claude/... | β User-only |
Verify permissions:
# macOS/Linux - Should be readable only by you
ls -la ~/Library/Application\ Support/Claude/
# Expected: -rw-------
For more on responsible AI usage, see the Understanding AI Safety, Ethics, and Limitations guide.
Principle of Least Privilege
By Service Type
| Service | Minimum Required | Avoid |
|---|---|---|
| GitHub | repo:read, specific repos | admin:org, all repos |
| AWS | Read-only, specific resources | AdministratorAccess |
| Slack | Specific channels, read-only | Workspace admin |
| Filesystem | Specific directories | Home directory |
| Database | Read-only, specific tables | DBA privileges |
GitHub Token Permissions
For Code Review (Read-Only):
βοΈ repo (read only)
βοΈ read:org
β write:packages
β admin:org
β delete_repo
For PR Creation (Limited Write):
βοΈ repo (read & write)
βοΈ read:org
β admin:org
β delete_repo
AWS IAM Policies
Minimal S3 Read:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::specific-bucket",
"arn:aws:s3:::specific-bucket/*"
]
}
]
}
Filesystem Restrictions
{
"mcpServers": {
"filesystem": {
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/me/projects/safe-project" // β
Specific folder
// NOT "/Users/me" // β Home directory
]
}
}
}
For more on file access patterns, see the Filesystem MCP guide.
Token Scoping Strategies
Strategy 1: One Token Per Service
{
"mcpServers": {
"github": {
"env": { "GITHUB_TOKEN": "ghp_repo_readonly_token" }
},
"slack": {
"env": { "SLACK_BOT_TOKEN": "xoxb_channel_readonly" }
},
"aws": {
"env": { "AWS_ACCESS_KEY_ID": "AKIA_readonly_key" }
}
}
}
Strategy 2: Environment Separation
{
"mcpServers": {
"github-prod": {
"env": { "GITHUB_TOKEN": "ghp_prod_readonly" }
},
"github-dev": {
"env": { "GITHUB_TOKEN": "ghp_dev_full_access" }
}
}
}
Strategy 3: Read-Only by Default
Start with read-only access, upgrade only when needed:
Week 1: Read-only access ββββββΆ Verify patterns
Week 2: Same ββββββββββββββββββΆ Build confidence
Week 3: Selective write βββββββΆ Specific operations only
Week 4: Review and audit ββββββΆ Adjust as needed
Audit and Monitoring
Enable Service-Side Logging
| Service | How to Enable | Whatβs Logged |
|---|---|---|
| GitHub | Settings β Audit log | API calls, repos accessed |
| AWS | CloudTrail | All API calls |
| Slack | Workspace Analytics | Messages, channels |
| Cloudflare | Audit Logs | Zone changes, API calls |
| Sentry | API Logs | Issues accessed |
What to Monitor
β
Monitor:
- API call frequency
- Unusual access patterns
- Failed authentication attempts
- Access to sensitive resources
β οΈ Alert on:
- Tokens used from new locations
- Access outside normal hours
- Rate limit warnings
- Permission denied errors
Monthly Security Review
1. Review API key usage
2. Check access logs for anomalies
3. Revoke unused tokens
4. Update permissions if scope creep
5. Rotate credentials if needed
For more on AI agent capabilities, see the AI Agents guide.
Secure Configuration Patterns
Pattern 1: Read-Only Production
{
"mcpServers": {
"github-prod": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PROD_READONLY}"
}
}
}
}
Pattern 2: Restricted Filesystem
{
"mcpServers": {
"files-readonly": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"--read-only",
"/safe/directory/only"
]
}
}
}
Pattern 3: Scoped Database
{
"mcpServers": {
"postgres": {
"env": {
"DATABASE_URL": "postgresql://mcp_reader:pass@host/db"
// User has SELECT only, no INSERT/UPDATE/DELETE
}
}
}
}
Pattern 4: Split by Sensitivity
{
"mcpServers": {
// High security - minimal access
"aws-prod": {
"env": {
"AWS_PROFILE": "mcp-prod-readonly"
}
},
// Lower security - more access
"aws-dev": {
"env": {
"AWS_PROFILE": "mcp-dev-full"
}
}
}
}
Common Security Mistakes
Mistake 1: Overly Broad Permissions
β "I'll just give it admin access to make it work"
β
"Start with minimum, add only what's needed"
Mistake 2: Sharing Credentials
β Using the same token for personal and MCP use
β
Create dedicated MCP tokens for audit clarity
Mistake 3: Forgetting File Access
β Granting home directory to Filesystem MCP
β
Grant only specific project folders
Mistake 4: Committing Config Files
β Pushing claude_desktop_config.json to GitHub
β
Add to .gitignore, use environment variables
Mistake 5: Never Rotating Keys
β Using the same token for years
β
Rotate quarterly or after any security event
Emergency Procedures
If a Token is Compromised
Immediate Actions (within minutes):
- Revoke the token at the service
- Create new token with same permissions
- Update MCP config with new token
- Review audit logs for unauthorized access
Follow-up (within hours):
- Assess impact - what was accessed?
- Notify stakeholders if sensitive data involved
- Review how compromise occurred
- Implement preventive measures
Service-Specific Revocation
| Service | How to Revoke |
|---|---|
| GitHub | Settings β Developer settings β Tokens β Revoke |
| AWS | IAM β Users β Security credentials β Deactivate |
| Slack | Workspace settings β Apps β Revoke |
| Cloudflare | Profile β API Tokens β Revoke |
Enterprise Security Considerations
Team Usage
| Practice | Implementation |
|---|---|
| Shared service accounts | Create MCP-specific service accounts |
| Centralized secrets | Use secret managers (Vault, AWS SM) |
| Access reviews | Monthly review of MCP permissions |
| Offboarding | Include MCP token revocation in process |
Compliance
| Requirement | MCP Consideration |
|---|---|
| SOC 2 | Document MCP access, enable audit logs |
| GDPR | Ensure no personal data via Filesystem |
| HIPAA | Avoid healthcare data in MCP-accessible systems |
| PCI | Never give MCP access to cardholder data |
Security Checklist
Initial Setup
β Create dedicated API tokens for MCP
β Apply minimum required permissions
β Store credentials securely
β Add config files to .gitignore
β Verify file permissions on config
β Test with read-only first
Ongoing Maintenance
β Review access logs monthly
β Rotate credentials quarterly
β Revoke unused tokens
β Update permissions as needs change
β Audit which servers are configured
Before Production Use
β Use read-only for production data
β Enable service audit logs
β Document what AI can access
β Set up monitoring alerts
β Create incident response plan
Summary
MCP security is about layers of protection:
- β Layer 1: You control which servers run
- β Layer 2: Token scopes limit each server
- β Layer 3: Service policies restrict resources
2025 Security Standards:
- OAuth 2.1 with PKCE (RFC 9700)
- Resource Indicators (RFC 8707)
- No token passthrough to upstream APIs
- Zero Trust architecture alignment
- Separated authorization/resource servers
Key Practices:
| Practice | Why |
|---|---|
| Least privilege | Limit blast radius |
| Scoped tokens | Clear audit trail |
| Secure storage | Prevent exposure |
| Regular audits | Catch issues early |
| Key rotation | Limit compromise impact |
Start secure, stay secure - itβs much easier to add permissions than to recover from a security incident.
Next: Learn about Combining Multiple MCPs β for powerful workflows.
Questions about MCP security? Check the MCP specification or RFC 9700 for OAuth best practices.