🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

database-admin-mcp

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

database-admin-mcp

MCP server for database administration - schema inspection, query optimization, data exploration, and migration helpers for PostgreSQL and MySQL

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

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-mcp

Or use with npx:

npx database-admin-mcp

Configuration

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/dbname

Using 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          # optional

Safety 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

ToolDescription
list_tablesList all tables with size and index count
describe_tableGet columns, types, indexes, and foreign keys
get_relationshipsView all foreign key relationships as a graph
get_connection_infoShow current connection settings

Data Tools

ToolDescription
sample_dataRetrieve sample rows from a table
execute_queryRun SQL queries (respects read-only mode)

Optimization Tools

ToolDescription
analyze_indexesGet index usage stats and suggestions
explain_queryGet query execution plan with recommendations

Migration Tools

ToolDescription
generate_migrationGenerate 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=false

  • Row limits: Results are limited to DB_MAX_ROWS (default 1000) to prevent memory issues

  • Connection 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_indexes for index analysis
  • JSON query plans with cost estimates

MySQL

  • Full feature support
  • Uses information_schema for metadata
  • SHOW TABLE STATUS for storage analysis
  • Standard EXPLAIN output

License

MIT License - see LICENSE

Keywords

mcp

FAQs

Package last updated on 27 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts