Security and Scope Controls
Secure RetainDB MCP with per-environment keys, scoped defaults, local allowlists, and an operational model that matches the current server behavior.
Applies to: RetainDB MCP
Secure RetainDB MCP as if it were a production integration point, not a convenience script. It can read local files, search code, ingest sources, and write durable memory, so the surrounding scope model matters.
Key management
Use separate rdb_* keys per environment:
# Development
RETAINDB_API_KEY=rdb_dev_...
# Production
RETAINDB_API_KEY=rdb_prod_...Example split config:
{
"mcpServers": {
"RetainDB-dev": {
"command": "npx",
"args": ["-y", "@retaindb/mcp-server@latest"],
"env": {
"RETAINDB_API_KEY": "rdb_dev_...",
"RETAINDB_PROJECT": "project-dev"
}
},
"RetainDB-prod": {
"command": "npx",
"args": ["-y", "@retaindb/mcp-server@latest"],
"env": {
"RETAINDB_API_KEY": "rdb_prod_...",
"RETAINDB_PROJECT": "project-prod"
}
}
}
}Scope controls that matter most
Default project scope
Set RETAINDB_PROJECT whenever the server should stay anchored to one project by default.
Runtime mode
remoteis the safe defaultlocalenables local ingest behaviorautomixes remote and local behavior when available
Local filesystem allowlist
If you enable local ingest or want controlled local scans, restrict roots explicitly:
RETAINDB_MCP_MODE=auto
RetainDB_LOCAL_ALLOWLIST=/workspace/app,/workspace/docsGenerated scoped configs
Use the built-in scope generator when you want per-client or per-source configs:
retaindb-context-mcp scope --project my-project --client claude
retaindb-context-mcp scope --project my-project --source github --client vscodeTool-level operational guidance
- prefer
search,search_code,grep, andreadfor day-to-day coding workflows - reserve write-capable verbs like
remember,record, andlearnfor trusted workflows - use namespaced tools like
context.add_sourceormemory.addonly when you need the explicit advanced contract
Monitoring and traceability
Track:
- which project a server instance defaults to
- which host/client is allowed to invoke it
- whether local mode is enabled
- trace IDs or tool result metadata returned by the MCP workflow
When something looks wrong, first verify whether the server instance is over-scoped before assuming a product bug.
Key rotation
Operationally:
- create a replacement
rdb_*key - update the MCP host config
- restart the MCP host
- revoke the old key once the new config is confirmed
Do not rotate keys by editing live configs without a restart plan, or you will create hard-to-debug partial failures.
Best practices
- never commit
.env, local MCP settings, or copied secrets - keep separate keys per environment and per trust boundary
- keep production servers in
remotemode unless local access is intentionally required - use
RetainDB_LOCAL_ALLOWLISTinstead of broad filesystem access - validate that a scoped config still surfaces only the tools and content you expect
Next step
Was this page helpful?
Your feedback helps us prioritize docs improvements weekly.