MCP server for database administration - schema inspection, query optimization, data exploration, and migration helpers for PostgreSQL and MySQL
npm install database-admin-mcpA Model Context Protocol (MCP) server for database administration. Provides AI assistants with tools for schema inspection, query optimization, data exploration, and migration helpers.
Supports PostgreSQL and MySQL.
- Schema Inspection: List tables, describe columns, view indexes and foreign keys
- Data Exploration: Sample rows from tables with configurable limits
- Query Execution: Run SQL queries (read-only by default for safety)
- Index Analysis: Find unused indexes, missing FK indexes, get optimization suggestions
- Query Plans: EXPLAIN queries with cost analysis and recommendations
- Migration Generation: Generate up/down migration scripts for schema changes
- Relationship Mapping: Visualize foreign key relationships across tables
- Safety First: Read-only mode by default, write operations require explicit opt-in
``bash`
npm install -g database-admin-mcp
Or use with npx:
`bash`
npx database-admin-mcp
Add to claude_desktop_config.json:
`json`
{
"mcpServers": {
"database": {
"command": "npx",
"args": ["database-admin-mcp"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb"
}
}
}
}
Connection (choose one method):
Using connection string:
`bash`
DATABASE_URL=postgresql://user:pass@localhost:5432/dbnameor
DATABASE_URL=mysql://user:pass@localhost:3306/dbname
Using individual variables:
`bash`
DB_TYPE=postgres # or mysql
DB_HOST=localhost
DB_PORT=5432 # 3306 for MySQL
DB_NAME=mydb
DB_USER=myuser
DB_PASSWORD=mypassword
DB_SSL=true # optional
Safety settings:
`bash`
DB_READ_ONLY=true # Default: true (prevents INSERT/UPDATE/DELETE)
DB_MAX_ROWS=1000 # Default: 1000 (max rows returned per query)
| Tool | Description |
|------|-------------|
| list_tables | List all tables with size and index count |describe_table
| | Get columns, types, indexes, and foreign keys |get_relationships
| | View all foreign key relationships as a graph |get_connection_info
| | Show current connection settings |
| Tool | Description |
|------|-------------|
| sample_data | Retrieve sample rows from a table |execute_query
| | Run SQL queries (respects read-only mode) |
| Tool | Description |
|------|-------------|
| analyze_indexes | Get index usage stats and suggestions |explain_query
| | Get query execution plan with recommendations |
| Tool | Description |
|------|-------------|
| generate_migration | Generate up/down SQL for schema changes |
"Show me all tables in the database"
`$3
`
"What columns does the users table have?"
`$3
`
"Show me 5 sample rows from the orders table"
`$3
`
"Are there any unused indexes on the products table?"
`$3
`
"Generate a migration to add an email column to the customers table"
`$3
`
"Why is this query slow: SELECT * FROM orders WHERE customer_id = 123"
`Safety Features
1. Read-only by default: Write operations (INSERT, UPDATE, DELETE, DROP, etc.) are blocked unless
DB_READ_ONLY=false2. Row limits: Results are limited to
DB_MAX_ROWS (default 1000) to prevent memory issues3. Connection pooling: Efficient connection management with automatic cleanup
4. No credentials in output: Connection info tool hides passwords
Supported Databases
$3
- Full feature support
- Schema-aware (supports multiple schemas)
- Uses pg_stat_user_indexes for index analysis
- JSON query plans with cost estimates$3
- Full feature support
- Uses information_schema for metadata
- SHOW TABLE STATUS` for storage analysisMIT License - see LICENSE