API Key Cycling Guide for Blockchain MCP Servers
๐ Security Noticeโ
This document provides instructions for rotating API keys and sensitive credentials used in blockchain MCP servers built according to BMCPS v3.0. Regular key rotation is a critical security practice.
โ ๏ธ IMPORTANT: Never commit API keys, private keys, or secrets to version control. Always use environment variables or secure secret management.
Table of Contentsโ
- Common API Keys in Blockchain MCP Servers
- When to Rotate Keys
- Step-by-Step Key Rotation
- Provider-Specific Instructions
- Verification Checklist
- Emergency Key Revocation
Common API Keys in Blockchain MCP Serversโ
1. RPC Provider API Keysโ
Used to connect to blockchain networks.
Providers:
- Alchemy - Ethereum, Polygon, Arbitrum, Base, etc.
- Infura - Ethereum, Polygon, Arbitrum
- QuickNode - Multi-chain support
- Ankr - Multi-chain support
- Helius - Solana
- GetBlock - Multi-chain support
Environment Variable: RPC_URL or \{BLOCKCHAIN\}_RPC_URL
Example:
ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY
POLYGON_RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEY
SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY
2. Blockchain Explorer API Keysโ
Used for transaction history and account lookups.
Providers:
- Etherscan - Ethereum
- Polygonscan - Polygon
- Arbiscan - Arbitrum
- Basescan - Base
- BscScan - BNB Chain
- Blockchair - Bitcoin
- XRPScan - XRP Ledger
Environment Variable: EXPLORER_API_KEY or \{BLOCKCHAIN\}_EXPLORER_API_KEY
Example:
ETHERSCAN_API_KEY=ABCDEFGHIJKLMNOPQRSTUVWXYZ123456
POLYGONSCAN_API_KEY=ABCDEFGHIJKLMNOPQRSTUVWXYZ123456
3. Price/Market Data API Keysโ
Used for token price queries and market data.
Providers:
- CoinGecko (Pro)
- CoinMarketCap
- Coinbase
- Messari
Environment Variable: PRICE_API_KEY or COINGECKO_API_KEY
Example:
COINGECKO_API_KEY=CG-XXXXXXXXXXXXXXXXXXXX
COINMARKETCAP_API_KEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
4. MCP Inspector/Testing Keysโ
Used during development and testing.
Environment Variable: MCP_TEST_KEY or INSPECTOR_API_KEY
5. Database/Storage API Keys (if applicable)โ
For caching or persistent storage.
Providers:
- Supabase
- MongoDB Atlas
- Redis Cloud
- PostgreSQL
Environment Variable: DATABASE_URL
When to Rotate Keysโ
Scheduled Rotation (Recommended)โ
- Every 90 days for production keys
- Every 30 days for development/testing keys
- Immediately after team member departure
Immediate Rotation Requiredโ
- Key Exposure: API key committed to public repository
- Security Breach: Unauthorized access detected
- Suspicious Activity: Unusual API usage patterns
- Compliance: Regulatory or audit requirements
- Service Compromise: Provider reports breach
Step-by-Step Key Rotationโ
Phase 1: Generate New Keys (Day 0)โ
For RPC Providers (Alchemy Example)โ
-
Log into Alchemy Dashboard
- Go to https://dashboard.alchemy.com/
- Navigate to "Apps"
-
Create New App
- Click "Create App"
- Name:
\{blockchain\}-mcp-server-v2(increment version) - Chain: Select your blockchain
- Network: Mainnet or Testnet
-
Get New API Key
- Click "View Key"
- Copy the new HTTPS endpoint
- Store securely (password manager)
-
Repeat for Each Blockchain
For Blockchain Explorers (Etherscan Example)โ
-
Log into Etherscan
- Go to https://etherscan.io/myapikey
- Login with your account
-
Generate New API Key
- Click "Add" to create new API key
- Name:
mcp-server-2025-01(use date) - Copy the new key
-
Save Securely
Phase 2: Update Environment Variables (Day 0)โ
Local Developmentโ
-
Update
.env.localfile (NEVER commit this file)# Old keys (keep temporarily)
# ETH_RPC_URL_OLD=https://eth-mainnet.g.alchemy.com/v2/OLD_KEY
# New keys (active)
ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/NEW_KEY
POLYGON_RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/NEW_KEY
ETHERSCAN_API_KEY=NEW_ETHERSCAN_KEY
POLYGONSCAN_API_KEY=NEW_POLYGONSCAN_KEY -
Verify
.gitignoreincludes:.env
.env.local
.env.*.local
*.key
*.pem
secrets/
Production/Staging Environmentsโ
Option A: Environment Variables (Recommended)
For cloud deployments:
-
AWS Systems Manager Parameter Store
aws ssm put-parameter \
--name /mcp-server/eth/rpc-url \
--value "https://eth-mainnet.g.alchemy.com/v2/NEW_KEY" \
--type SecureString \
--overwrite -
Heroku Config Vars
heroku config:set ETH_RPC_URL="https://eth-mainnet.g.alchemy.com/v2/NEW_KEY" -
Vercel Environment Variables
- Dashboard โ Project โ Settings โ Environment Variables
- Update each key
- Redeploy
Option B: Secret Management Services
-
HashiCorp Vault
vault kv put secret/mcp-server \
eth_rpc_url="https://eth-mainnet.g.alchemy.com/v2/NEW_KEY" -
AWS Secrets Manager
aws secretsmanager update-secret \
--secret-id mcp-server/eth-rpc \
--secret-string '\{"rpc_url":"https://eth-mainnet.g.alchemy.com/v2/NEW_KEY"\}'
Phase 3: Test New Keys (Day 0)โ
Run Verification Testsโ
-
Local Testing
# Load new environment
source .env.local
# Build and test
npm run build
npm run test
# Manual inspection
npm run inspect -
Test Each Tool
# Test RPC connectivity
curl -X POST https://eth-mainnet.g.alchemy.com/v2/NEW_KEY \
-H "Content-Type: application/json" \
-d '\{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1\}'
# Expected: \{"jsonrpc":"2.0","id":1,"result":"0x..."\} -
Verify in MCP Inspector
- Open MCP Inspector
- Test
\{prefix\}_get_chain_info - Test
\{prefix\}_get_balancewith known address - Test
\{prefix\}_get_transaction_history
-
Check Logs
# Look for authentication errors
grep -i "auth\|unauthorized\|forbidden" logs/*.log
Phase 4: Deploy Changes (Day 1-2)โ
Deployment Strategyโ
Blue-Green Deployment (Recommended)
- Deploy new version with new keys to "green" environment
- Test thoroughly in green environment
- Switch traffic from "blue" to "green"
- Monitor for 24 hours
- Decommission "blue" environment
Rolling Update
- Update keys in staging environment first
- Test for 24 hours in staging
- Gradually roll out to production (10% โ 50% โ 100%)
- Monitor error rates and latency
Phase 5: Revoke Old Keys (Day 7)โ
โ ๏ธ Wait Period: Keep old keys active for 7 days to ensure smooth transition.
Alchemy (RPC Provider)โ
-
Archive Old App
- Dashboard โ Apps
- Click on old app
- "Archive App" (don't delete immediately)
-
Verify No Usage
- Check analytics for requests on old key
- Should be 0 requests after migration
-
Delete After 30 Days
Etherscan (Explorer API)โ
-
Deactivate Old Key
- Dashboard โ API Keys
- Click "Delete" on old key
-
Confirm Deletion
Document the Rotationโ
Update your internal documentation:
## API Key Rotation Log
| Date | Provider | Key Name | Rotated By | Reason |
|------|----------|----------|------------|--------|
| 2025-01-15 | Alchemy | eth-mainnet-v2 | DevOps | Scheduled 90-day rotation |
| 2025-01-15 | Etherscan | api-key-2025-01 | DevOps | Scheduled 90-day rotation |
Provider-Specific Instructionsโ
Alchemyโ
Dashboard: https://dashboard.alchemy.com/
Steps:
- Apps โ Create App
- Select Chain & Network
- Copy HTTPS endpoint
- Update
\{BLOCKCHAIN\}_RPC_URL - Archive old app after 7 days
Rate Limits: Check your plan's compute units
Infuraโ
Dashboard: https://infura.io/dashboard
Steps:
- Create New Project
- Copy Project ID
- Update RPC URL:
https://mainnet.infura.io/v3/PROJECT_ID - Delete old project after verification
QuickNodeโ
Dashboard: https://dashboard.quicknode.com/
Steps:
- Create Endpoint
- Select Chain & Network
- Copy HTTP Provider URL
- Update environment variable
- Delete old endpoint after 7 days
Helius (Solana)โ
Dashboard: https://dashboard.helius.dev/
Steps:
- Create New API Key
- Copy key
- Update
SOLANA_RPC_URL - Deactivate old key after verification
Etherscan/Polygonscan/BscScanโ
Dashboard: https://etherscan.io/myapikey (varies by chain)
Steps:
- Login โ My API Keys
- Add new API key
- Name with date (e.g.,
mcp-2025-01) - Copy key
- Delete old key after 7 days
Verification Checklistโ
After rotating keys, verify:
Immediate Checks (Day 0)โ
- All new keys stored in secure location (password manager)
-
.env.localupdated with new keys -
.env.localNOT committed to git -
.gitignoreincludes.env* - Build succeeds:
npm run build - Tests pass:
npm run test - MCP Inspector connects successfully
- Basic tools work (
get_chain_info,get_balance)
Pre-Production Checks (Day 1)โ
- Staging environment updated
- Staging tests pass
- Rate limits verified (no 429 errors)
- Error monitoring configured
- Rollback plan documented
Production Checks (Day 2)โ
- Production environment updated
- Health checks passing
- Error rates normal (<0.1%)
- Latency within SLA
- No authentication errors in logs
Post-Rotation Checks (Day 7)โ
- Old keys showing zero usage
- No alerts or incidents
- Old keys archived/deleted
- Rotation documented in change log
- Next rotation scheduled (90 days)
Emergency Key Revocationโ
If Keys Are Compromisedโ
Immediate Actions (Within 1 Hour):
-
Revoke Exposed Keys
- Log into each provider dashboard
- Delete/deactivate exposed keys immediately
- Document time of revocation
-
Generate Emergency Replacement Keys
- Create new keys with emergency naming (
emergency-2025-01-15) - Deploy immediately to production
- Create new keys with emergency naming (
-
Update All Environments
# Emergency deployment script
./scripts/emergency-key-rotation.sh -
Notify Team
- Alert security team
- Post in incident channel
- Document incident timeline
-
Assess Damage
- Check API usage logs for unauthorized requests
- Review transaction history for suspicious activity
- Check for data exfiltration
-
Monitor Closely
- 24-hour monitoring
- Alert on any unusual patterns
- Review logs every 2 hours
If Keys Committed to Gitโ
Critical Steps:
-
Immediately Revoke Keys
- Even if you delete the commit, keys are in git history
- Revoke ALL exposed keys immediately
-
Rewrite Git History (if caught quickly)
# Remove sensitive file from entire history
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch .env" \
--prune-empty --tag-name-filter cat -- --all
# Force push (โ ๏ธ coordinate with team)
git push origin --force --all -
Notify Repository Host
- GitHub: Use "Report a security vulnerability"
- GitLab: Contact support to purge sensitive data
-
Rotate All Keys
- Even unrelated keys should be rotated
- Assume all secrets in the repo are compromised
-
Post-Mortem
- Document how keys were exposed
- Update processes to prevent recurrence
- Implement pre-commit hooks:
# .git/hooks/pre-commit
#!/bin/bash
if git diff --cached --name-only | grep -E "\.env|\.key|\.pem"; then
echo "โ Error: Attempting to commit secret file"
exit 1
fi
Best Practicesโ
Key Managementโ
-
Never Hardcode Keys
// โ NEVER DO THIS
const apiKey = "abc123...";
// โ ALWAYS USE ENVIRONMENT VARIABLES
const apiKey = process.env.API_KEY; -
Use Different Keys Per Environment
- Development:
dev-api-key - Staging:
staging-api-key - Production:
prod-api-key
- Development:
-
Implement Key Rotation Automation
# Cron job for quarterly rotation reminder
0 0 1 */3 * /usr/local/bin/rotation-reminder.sh -
Use Secret Management Services
- AWS Secrets Manager
- HashiCorp Vault
- Azure Key Vault
- Google Secret Manager
-
Least Privilege Principle
- Create API keys with minimum required permissions
- Separate read-only keys from write keys
Monitoringโ
-
Set Up Alerts
- Alert on authentication failures
- Alert on rate limit exceeded (429 errors)
- Alert on unusual usage patterns
-
Log API Key Usage
logger.info('API request', \{
provider: 'alchemy',
keyPrefix: apiKey.slice(0, 8) + '...', // Never log full key
endpoint: '/v2/...',
timestamp: Date.now()
\}); -
Regular Audits
- Monthly review of active API keys
- Quarterly security audit
- Annual penetration testing
Compliance & Documentationโ
Required Documentationโ
Maintain these records:
-
API Key Inventory
Provider,Key Name,Environment,Created,Last Rotated,Next Rotation,Owner
Alchemy,eth-mainnet-v3,production,2025-01-15,2025-01-15,2025-04-15,[email protected] -
Rotation Schedule
| Next Rotation Date | Provider | Environment |
|--------------------|----------|-------------|
| 2025-04-15 | Alchemy | Production |
| 2025-04-15 | Etherscan | Production | -
Incident Log Track all key-related incidents
-
Access Log Who has access to which keys
Compliance Requirementsโ
- SOC 2: Key rotation every 90 days
- PCI DSS: Quarterly key rotation for payment systems
- ISO 27001: Documented key management procedures
- GDPR: Secure key storage and access controls
Emergency Contactsโ
Provider Supportโ
| Provider | Support URL | Emergency Contact |
|---|---|---|
| Alchemy | https://docs.alchemy.com/support | [email protected] |
| Infura | https://infura.io/contact | [email protected] |
| QuickNode | https://quicknode.com/contact | [email protected] |
| Etherscan | https://etherscan.io/contactus | [email protected] |
Additional Resourcesโ
Last Updated: January 2025 Document Owner: Security Team Review Cycle: Quarterly
This document is part of the Blockchain MCP Standard v3.0 (BMCPS v3.0) security documentation.