Skip to main content

Database Configuration for MCPHub

Overview

MCPHub supports storing configuration data in a PostgreSQL database as an alternative to the mcp_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. MCPHub 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 a docker-compose.yml:
Run with:

2. Manual Setup

Step 1: Setup PostgreSQL Database

Step 2: Install MCPHub

Step 3: Set Environment Variables

Create a .env file:

Step 4: Run Migration (Optional)

If you have an existing mcp_settings.json file, migrate it:
Or let MCPHub auto-migrate on first startup.

Step 5: Start MCPHub

Migration from File-Based to Database

MCPHub provides automatic migration on first startup when database mode is enabled. However, you can also run the migration manually.

Automatic Migration

When you start MCPHub with USE_DB=true for the first time:
  1. MCPHub connects to the database
  2. Checks if any users exist in the database
  3. If no users found, automatically migrates from mcp_settings.json
  4. Creates all tables and imports all data

Manual Migration

Run the migration script:
The migration will:
  • ✅ 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
The web dashboard works exactly the same way, but now stores changes in the database instead of the file.

Database Schema

MCPHub 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:
  1. Set USE_DB=false or remove DB_URL and USE_DB environment variables
  2. Restart MCPHub
  3. MCPHub will use mcp_settings.json again
Note: Changes made in database mode won’t be reflected in the file unless you manually export them.

Troubleshooting

Connection Refused

Solution: Check that PostgreSQL is running and accessible:

Authentication Failed

Solution: Verify database credentials in DB_URL environment variable.

Migration Failed

Solution:
  1. Check that mcp_settings.json exists and is valid JSON
  2. Verify database connection
  3. Check logs for specific error messages
  4. 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:
  1. Whether a previous migration partially completed
  2. Manual table creation conflicts
  3. Run with synchronize: false in database config if needed

Environment Variables Reference

*Required for database mode. Simply setting DB_URL enables database mode automatically

Security Considerations

  1. Database Credentials: Store database credentials securely, use environment variables or secrets management
  2. Network Access: Restrict database access to MCPHub instances only
  3. Encryption: Use SSL/TLS for database connections in production:
  4. Backup: Regularly backup your database
  5. 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
File mode may be faster for:
  • Single user setups
  • Read-heavy workloads with infrequent changes
  • Development/testing environments