Database Configuration for Pcnaid MCP Hub
Overview
Pcnaid MCP Hub supports storing configuration data in a PostgreSQL database as an alternative to themcp_settings.json file. Database mode provides enhanced persistence and scalability for production environments and enterprise deployments.
Why Use Database Configuration?
Core Benefits:- ✅ Better Persistence - Configuration stored in a professional database with transaction support and data integrity
- ✅ High Availability - Leverage database replication and failover capabilities
- ✅ Enterprise Ready - Meets enterprise data management and compliance requirements
- ✅ Backup & Recovery - Use mature database backup tools and strategies
Environment Variables
Required for Database Mode
Simplified Configuration: You only need to set
DB_URL to enable database mode. Pcnaid MCP Hub will automatically detect and enable database mode when DB_URL is present. Use USE_DB=false to explicitly disable database mode even when DB_URL is set.Setup Instructions
1. Using Docker
Option A: Using External Database
If you already have a PostgreSQL database:Option B: Using PostgreSQL as a separate service
Create adocker-compose.yml:
2. Manual Setup
Step 1: Setup PostgreSQL Database
Step 2: Install Pcnaid MCP Hub
Step 3: Set Environment Variables
Create a.env file:
Step 4: Run Migration (Optional)
If you have an existingmcp_settings.json file, migrate it:
Step 5: Start Pcnaid MCP Hub
Migration from File-Based to Database
Pcnaid MCP Hub provides automatic migration on first startup when database mode is enabled. However, you can also run the migration manually.Automatic Migration
When you start Pcnaid MCP Hub withUSE_DB=true for the first time:
- Pcnaid MCP Hub connects to the database
- Checks if any users exist in the database
- If no users found, automatically migrates from
mcp_settings.json - Creates all tables and imports all data
Manual Migration
Run the migration script:- ✅ Create database tables if they don’t exist
- ✅ Import all users with hashed passwords
- ✅ Import all MCP server configurations
- ✅ Import all groups
- ✅ Import system configuration
- ✅ Import user-specific configurations
- ✅ Skip existing records (safe to run multiple times)
Configuration After Migration
Once running in database mode, all configuration changes are stored in the database:- User management via
/api/users - Server management via
/api/servers - Group management via
/api/groups - System settings via
/api/system/config
Database Schema
Pcnaid MCP Hub creates the following tables:- users - User accounts and authentication
- servers - MCP server configurations
- groups - Server groups
- system_config - System-wide settings
- user_configs - User-specific settings
- vector_embeddings - Vector search data (for smart routing)
Backup and Restore
Backup
Restore
Switching Back to File-Based Config
If you need to switch back to file-based configuration:- Set
USE_DB=falseor removeDB_URLandUSE_DBenvironment variables - Restart Pcnaid MCP Hub
- Pcnaid MCP Hub will use
mcp_settings.jsonagain
Troubleshooting
Connection Refused
Authentication Failed
DB_URL environment variable.
Migration Failed
- Check that
mcp_settings.jsonexists and is valid JSON - Verify database connection
- Check logs for specific error messages
- Ensure database user has CREATE TABLE permissions
Tables Already Exist
Database tables are automatically created if they don’t exist. If you get errors about existing tables, check:- Whether a previous migration partially completed
- Manual table creation conflicts
- Run with
synchronize: falsein database config if needed
Environment Variables Reference
| Variable | Required | Default | Description |
|---|---|---|---|
DB_URL | Yes* | - | Full PostgreSQL connection URL. Setting this automatically enables database mode |
USE_DB | No | auto | Explicitly enable/disable database mode. If not set, auto-detected based on DB_URL presence |
MCPHUB_SETTING_PATH | No | - | Path to mcp_settings.json (for migration) |
DB_URL enables database mode automatically
Security Considerations
- Database Credentials: Store database credentials securely, use environment variables or secrets management
- Network Access: Restrict database access to Pcnaid MCP Hub instances only
- Encryption: Use SSL/TLS for database connections in production:
- Backup: Regularly backup your database
- Access Control: Use strong database passwords and limit user permissions
Performance
Database mode offers better performance for:- Multiple concurrent users
- Frequent configuration changes
- Large number of servers/groups
- Single user setups
- Read-heavy workloads with infrequent changes
- Development/testing environments