API Key Authentication
Learn how to authenticate with PlexMCP using API keys.
Overview
API keys are the primary way to authenticate with PlexMCP. Each key:
- Is scoped to your organization
- Can access specific MCPs
- Has optional expiration
- Tracks usage independently
Getting Your API Key
From the Dashboard
- Log in to dashboard.plexmcp.com
- Navigate to API Keys
- Click Create API Key
- Configure your key:
- Name: Descriptive identifier
- Description: Usage notes
- Expiration: When it expires
- Permissions: Which MCPs to access
- Click Create
- Copy the key immediately
Your API key is only shown once. Copy it before closing the dialog.
Using Your API Key
HTTP Header
Include the key in the Authorization header:
curl -X POST https://api.plexmcp.com/v1/mcp/invoke \
-H "Authorization: Bearer pk_live_xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{...}'
SDK Initialization
import { PlexMCP } from '@plexmcp/sdk';
const client = new PlexMCP({
apiKey: 'pk_live_xxxxxxxx'
});
Environment Variables
Best practice is to use environment variables:
# .env file
PLEXMCP_API_KEY=pk_live_xxxxxxxx
const client = new PlexMCP({
apiKey: process.env.PLEXMCP_API_KEY
});
Key Permissions
All MCPs
Grant access to all current and future MCPs:
Permissions: All MCPs
Specific MCPs
Limit access to selected MCPs only:
Permissions: Weather API, Calculator
Key Expiration
Never Expire
For long-term production keys. Use with rotation policy.
Set Expiration
Common expiration periods:
- 30 days: Contractor access
- 90 days: Regular rotation
- 1 year: Long-term with review
Security Best Practices
1. Use Environment Variables
Never hardcode keys:
// Bad
const apiKey = "pk_live_xxxxx";
// Good
const apiKey = process.env.PLEXMCP_API_KEY;
2. Don't Commit Keys
Add to .gitignore:
.env
.env.local
*.env
3. Use Separate Keys
Create different keys for:
- Production
- Staging
- Development
- CI/CD
4. Minimal Permissions
Only grant access to needed MCPs.
5. Rotate Regularly
Set a rotation schedule:
- Create new key
- Update applications
- Verify new key works
- Revoke old key
6. Monitor Usage
Check dashboard for:
- Unusual request volume
- Unexpected error rates
- Unknown client IPs
Revoking Keys
If a key is compromised:
- Go to API Keys
- Find the key
- Click Revoke
- Confirm revocation
The key stops working immediately.
Troubleshooting
Invalid API Key
Error: 401 Unauthorized - Invalid or missing API key
Causes:
- Missing Authorization header
- Wrong key format
- Key revoked or expired
Fix: Verify the complete key is included with Bearer prefix.
Key Not Working
- Check key was copied completely
- Verify no extra whitespace
- Confirm key isn't revoked
- Check expiration date
MCP Access Denied
Error: 403 Forbidden - API key does not have access to this MCP
Fix: Update key permissions to include the MCP, or create a new key with access.