database-admin-mcp
v1.0.1
Published
MCP server for database administration - schema inspection, query optimization, data exploration, and migration helpers for PostgreSQL and MySQL
Maintainers
Readme
Database Admin MCP Server
A 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.
Features
- 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
Installation
npm install -g database-admin-mcpOr use with npx:
npx database-admin-mcpConfiguration
Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"database": {
"command": "npx",
"args": ["database-admin-mcp"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb"
}
}
}
}Environment Variables
Connection (choose one method):
Using connection string:
DATABASE_URL=postgresql://user:pass@localhost:5432/dbname
# or
DATABASE_URL=mysql://user:pass@localhost:3306/dbnameUsing individual variables:
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 # optionalSafety settings:
DB_READ_ONLY=true # Default: true (prevents INSERT/UPDATE/DELETE)
DB_MAX_ROWS=1000 # Default: 1000 (max rows returned per query)Available Tools
Schema Tools
| 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 |
Data Tools
| Tool | Description |
|------|-------------|
| sample_data | Retrieve sample rows from a table |
| execute_query | Run SQL queries (respects read-only mode) |
Optimization Tools
| Tool | Description |
|------|-------------|
| analyze_indexes | Get index usage stats and suggestions |
| explain_query | Get query execution plan with recommendations |
Migration Tools
| Tool | Description |
|------|-------------|
| generate_migration | Generate up/down SQL for schema changes |
Examples
List all tables
"Show me all tables in the database"Describe a table
"What columns does the users table have?"Sample data
"Show me 5 sample rows from the orders table"Analyze indexes
"Are there any unused indexes on the products table?"Generate migration
"Generate a migration to add an email column to the customers table"Query optimization
"Why is this query slow: SELECT * FROM orders WHERE customer_id = 123"Safety Features
Read-only by default: Write operations (INSERT, UPDATE, DELETE, DROP, etc.) are blocked unless
DB_READ_ONLY=falseRow limits: Results are limited to
DB_MAX_ROWS(default 1000) to prevent memory issuesConnection pooling: Efficient connection management with automatic cleanup
No credentials in output: Connection info tool hides passwords
Supported Databases
PostgreSQL
- Full feature support
- Schema-aware (supports multiple schemas)
- Uses
pg_stat_user_indexesfor index analysis - JSON query plans with cost estimates
MySQL
- Full feature support
- Uses
information_schemafor metadata SHOW TABLE STATUSfor storage analysis- Standard EXPLAIN output
License
MIT License - see LICENSE
