The MCP (Model Context Protocol) Server provides AI assistants with standardized access to PostgreSQL systems through HTTP/HTTPS endpoints with authentication.
For complete documentation, visit docs.pgedge.com.
Before building the server, install the following tools:
- Go 1.24 or later.
- PostgreSQL 14 or later for the datastore.
- Network access to the PostgreSQL datastore.
The MCP Server includes the following features:
- The server uses HTTP/HTTPS transport with JSON-RPC 2.0.
- The server provides SQLite-based authentication with users, sessions, and API tokens.
- Role-based access control manages groups, privileges, and token scopes.
- The admin panel enables management of users, groups, and tokens.
- The server supports multiple databases with per-connection access levels.
- MCP tools provide interfaces for database operations.
- MCP resources expose schema and data access.
- MCP prompts guide common workflows.
- The LLM proxy supports Anthropic, OpenAI, Gemini, and Ollama.
- The server manages conversation history.
# Build the server
make build
# Run tests
make test
# Run linting
make lint-
Build the server:
make build
-
Create a user:
./bin/ai-dba-server -add-user -username admin
-
Create a service token:
./bin/ai-dba-server -add-token
-
Start the server:
./bin/ai-dba-server
Note: The
./bin/paths above apply to source builds only. Production deployments place binaries in different locations depending on the installation method. See the Installation Guide for production paths.
The server is configured via YAML configuration file and/or command line flags.
See examples/ai-dba-server.yaml for a
complete example configuration.
The following general options configure the server:
-config stringsets the path to a configuration file.-addr stringsets the HTTP server address; the default is:8080.-tlsenables TLS/HTTPS transport.-cert stringsets the path to a TLS certificate file.-key stringsets the path to a TLS key file.-chain stringsets the path to a TLS certificate chain file.-debugenables debug logging.-data-dir stringsets the data directory for the auth database and conversations.
The following options configure the database connection:
-db-host stringsets the database host.-db-port intsets the database port.-db-name stringsets the database name.-db-user stringsets the database user.-db-password stringsets the database password.-db-sslmode stringsets the database SSL mode; valid values are disable, require, verify-ca, and verify-full.
The following option configures request tracing:
-trace-file stringsets the path to a trace file for logging MCP requests and responses.
Authentication data is stored in a SQLite database (auth.db) within the data
directory. By default, this is ./data/auth.db relative to the server binary.
The auth store contains:
- Users and service accounts with password hashes, superuser flags, and group memberships.
- API tokens with expiry dates, owner references, and optional scope restrictions.
- Groups with nested membership and assigned connection, MCP, and admin privileges.
- Token scopes that restrict tokens to specific connections, MCP privileges, and admin permissions.
# Add a new user (interactive)
./bin/ai-dba-server -add-user
# Add a new user (non-interactive)
./bin/ai-dba-server -add-user -username alice -password "SecurePass123!"
# List all users
./bin/ai-dba-server -list-users
# Update a user
./bin/ai-dba-server -update-user -username alice
# Enable a user (also resets failed login attempts)
./bin/ai-dba-server -enable-user -username alice
# Disable a user
./bin/ai-dba-server -disable-user -username alice
# Delete a user
./bin/ai-dba-server -delete-user -username alice# Add a new token (interactive)
./bin/ai-dba-server -add-token
# Add a new token (non-interactive, specifying owner)
./bin/ai-dba-server -add-token \
-user alice \
-token-note "Production API" \
-token-expiry "90d"
# List all tokens
./bin/ai-dba-server -list-tokens
# Remove a token by ID or hash prefix
./bin/ai-dba-server -remove-token <token-id-or-hash>Token Expiry Formats:
30d- 30 days1y- 1 year2w- 2 weeks12h- 12 hoursnever- Token never expires
# Add a new RBAC group
./bin/ai-dba-server -add-group -group developers
# List all groups
./bin/ai-dba-server -list-groups
# Add a user to a group
./bin/ai-dba-server -add-member -username alice -group developers
# Remove a user from a group
./bin/ai-dba-server -remove-member -username alice -group developers
# Delete a group
./bin/ai-dba-server -delete-group -group developers
# Set superuser status for a user
./bin/ai-dba-server -set-superuser -username admin
# Remove superuser status from a user
./bin/ai-dba-server -unset-superuser -username admin# List all registered MCP privileges
./bin/ai-dba-server -list-privileges
# Grant a privilege to a group
./bin/ai-dba-server -grant-privilege -group developers -privilege query_database
# Revoke a privilege from a group
./bin/ai-dba-server -revoke-privilege -group developers -privilege query_database
# Grant connection access to a group
./bin/ai-dba-server -grant-connection -group developers -connection 1 \
-access-level read_write
# Show privileges for a group
./bin/ai-dba-server -show-group-privileges -group developersToken scopes restrict a token to a subset of the owner's permissions. The system supports three scope types: connections (with access levels), MCP privileges, and admin permissions.
# Show current scope for a token
./bin/ai-dba-server -show-token-scope -token-id 1
# Restrict token to specific connections
./bin/ai-dba-server -scope-token-connections -token-id 1 \
-scope-connections "1,2,3"
# Restrict token to specific MCP tools
./bin/ai-dba-server -scope-token-tools -token-id 1 \
-scope-tools "query_database,get_schema_info"
# Clear all scope restrictions from a token
./bin/ai-dba-server -clear-token-scope -token-id 1The server includes the following security features:
- Passwords are hashed using bcrypt with cost factor 12.
- Tokens are hashed using SHA256 for secure storage.
- The server supports configurable per-IP rate limiting.
- Accounts lock automatically after repeated failed login attempts.
- Each token receives an isolated database connection pool for session separation.
The server searches for configuration in the following order:
- Path specified via
-configflag /etc/pgedge/ai-dba-server.yaml(system-wide)./ai-dba-server.yaml(binary directory)
Key configuration sections:
http:
address: ":8080"
tls:
enabled: false
auth:
enabled: true
max_failed_attempts_before_lockout: 5
max_user_token_days: 90
rate_limit_window_minutes: 15
rate_limit_max_attempts: 10
database:
host: "localhost"
port: 5432
database: "ai_workbench"
user: "postgres"
sslmode: "prefer"See the Administrator's Guide for detailed information.
To report an issue with the software, visit: GitHub Issues
We welcome your project contributions; for more information, see docs/developer-guide/contributing.md.
For more information, visit docs.pgedge.com.
This project is licensed under the PostgreSQL License.