This guide helps you create and configure a Cloudflare API token with the correct permissions for the MCP Memory Service Cloudflare backend.
To use the Cloudflare backend, your API token must have these permissions:
- Permission:
Cloudflare D1:Edit - Purpose: Storing memory metadata, tags, and relationships
- Required: Yes
- Permission:
AI Gateway:EditorVectorize:Edit - Purpose: Storing and querying memory embeddings
- Required: Yes
- Permission:
AI Gateway:ReadorWorkers AI:Read - Purpose: Generating embeddings using Cloudflare's AI models
- Model Used:
@cf/baai/bge-base-en-v1.5 - Required: Yes
- Permission:
Account:Read - Purpose: Basic account-level operations
- Required: Yes
- Permission:
R2:Edit - Purpose: Large content storage (files > 1MB)
- Required: Only if using R2 for large content storage
-
Navigate to Cloudflare Dashboard
-
Create Custom Token
- Click "Create Token" > "Custom token"
-
Configure Token Permissions
- Token name:
MCP Memory Service Token(or similar) - Permissions: Add all required permissions listed above
- Account resources: Include your Cloudflare account
- Zone resources: Include required zones (or all zones)
- IP address filtering: Leave blank for maximum compatibility
- TTL: Set appropriate expiration date
- Token name:
-
Save and Copy Token
- Click "Continue to summary" > "Create Token"
- Important: Copy the token immediately - it won't be shown again
Add the token to your environment configuration:
# Add to .env file in project root
MCP_MEMORY_STORAGE_BACKEND=cloudflare
CLOUDFLARE_API_TOKEN=your_new_token_here
CLOUDFLARE_ACCOUNT_ID=your_account_id
CLOUDFLARE_D1_DATABASE_ID=your_d1_database_id
CLOUDFLARE_VECTORIZE_INDEX=your_vectorize_index_name{
"mcpServers": {
"memory": {
"command": "uv",
"args": [
"--directory", "path/to/mcp-memory-service",
"run", "python", "-m", "mcp_memory_service.server"
],
"env": {
"MCP_MEMORY_STORAGE_BACKEND": "cloudflare",
"CLOUDFLARE_API_TOKEN": "your_new_token_here",
"CLOUDFLARE_ACCOUNT_ID": "your_account_id",
"CLOUDFLARE_D1_DATABASE_ID": "your_d1_database_id",
"CLOUDFLARE_VECTORIZE_INDEX": "your_vectorize_index_name"
}
}
}
}Test your token configuration:
# Navigate to project directory
cd path/to/mcp-memory-service
# Test the configuration
uv run python -c "
import asyncio
from src.mcp_memory_service.storage.cloudflare import CloudflareStorage
import os
async def test():
storage = CloudflareStorage(
api_token=os.getenv('CLOUDFLARE_API_TOKEN'),
account_id=os.getenv('CLOUDFLARE_ACCOUNT_ID'),
vectorize_index=os.getenv('CLOUDFLARE_VECTORIZE_INDEX'),
d1_database_id=os.getenv('CLOUDFLARE_D1_DATABASE_ID')
)
await storage.initialize()
print('Token configuration successful!')
asyncio.run(test())
"- Symptom: "Cannot use the access token from location: [IP]"
- Cause: Token has IP address restrictions
- Solution: Remove IP restrictions or add current IP to allowlist
- Symptom: "The given account is not valid or is not authorized"
- Cause: Token lacks required service permissions
- Solution: Add missing permissions (D1, Vectorize, Workers AI)
- Symptom: "Authentication error" for specific services
- Cause: Token missing permissions for specific services
- Solution: Verify all required permissions are granted
- Symptom: "Invalid API Token"
- Cause: Token may be malformed or expired
- Solution: Create a new token or check token format
If you use Google SSO for Cloudflare:
-
Set Account Password
- Go to My Profile → Authentication
- Click "Set Password" to add a password to your account
- Use this password when prompted during token creation
-
Alternative: Global API Key
- Go to My Profile → API Tokens
- Scroll to "Global API Key" section
- Use Global API Key + email for authentication
- Minimal Permissions: Only grant permissions required for your use case
- Token Rotation: Regularly rotate API tokens (e.g., every 90 days)
- Environment Variables: Never commit tokens to version control
- IP Restrictions: Use IP restrictions in production environments
- Monitoring: Monitor token usage in Cloudflare dashboard
- Expiration: Set reasonable TTL for tokens
If authentication continues to fail:
-
Verify Configuration
- Check all environment variables are set correctly
- Confirm resource IDs (account, database, index) are accurate
-
Test Individual Services
- Test account access first
- Then test each service (D1, Vectorize, Workers AI) individually
-
Check Cloudflare Logs
- Review API usage logs in Cloudflare dashboard
- Look for specific error messages and timestamps
-
Validate Permissions
- Double-check all required permissions are selected
- Ensure permissions include both read and write access where needed
-
Network Issues
- Verify network connectivity to Cloudflare APIs
- Check if corporate firewall blocks API access
For additional help, see the Cloudflare Setup Guide or the main troubleshooting documentation.