DB Analyzer MCP
Provides read-only analysis of PostgreSQL databases, including schema introspection, table and relationship exploration, SELECT/EXPLAIN/SHOW/CTE query execution, index and constraint inspection, performance and health monitoring, and data quality checks.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
DB Analyzer MCP
A safe, read-only database analysis tool for AI assistants via the Model Context Protocol (MCP). Enables AI to understand your database schema, run analytics queries, and provide insights without any risk of data modification.
Features
31 Database Tools - Schema introspection, query execution, performance analysis, and more
Read-Only by Design - Only SELECT, EXPLAIN, SHOW, and WITH (CTE) queries allowed
Multi-Layer Security - SQL validation, identifier sanitization, query limits
PostgreSQL Support - Primary focus with architecture ready for MySQL/SQLite
Project-Local Config -
.db-mcp/folder for configuration, logs, and cached schemaZero Console Output - All logging to files (stdio reserved for MCP protocol)
Related MCP server: DB Insights MCP Server
Installation
# Clone the repository
git clone https://github.com/ariburaco/db-analyzer-mcp.git
cd db-analyzer-mcp
# Install dependencies
bun installConfiguration
Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"db-analyzer": {
"command": "bun",
"args": ["run", "/path/to/db-analyzer-mcp/src/index.ts"]
}
}
}VS Code with Claude Extension
Add to your VS Code settings or .mcp.json:
{
"mcpServers": {
"db-analyzer": {
"command": "bun",
"args": ["run", "/path/to/db-analyzer-mcp/src/index.ts"]
}
}
}Cursor IDE
Add to Cursor's MCP configuration:
{
"mcpServers": {
"db-analyzer": {
"command": "bun",
"args": ["run", "/path/to/db-analyzer-mcp/src/index.ts"]
}
}
}Quick Start
Initialize your project (creates
.db-mcp/folder):
Use db_init with projectPath="/path/to/your/project"Ensure your
.envfile has DATABASE_URL:
DATABASE_URL=postgresql://user:password@localhost:5432/mydbPull your database schema:
Use db_pull to introspect the databaseStart analyzing:
Use db_tables to see all tables
Use db_describe for table details
Use db_query to run SELECT queriesTools Reference
Schema Tools
Tool | Description |
| Initialize .db-mcp folder with configuration |
| Pull database schema using Drizzle or Prisma |
| Get cached schema information |
| List all tables with row counts and sizes |
| Complete table info: columns, indexes, FKs, samples |
| Get sample rows from a table |
Query Tools
Tool | Description |
| Execute read-only SELECT queries |
| Run EXPLAIN ANALYZE for query optimization |
| Execute SQL from .sql/.txt file (for large queries with embeddings) |
Analytics Tools
Tool | Description |
| Database statistics: tables, rows, size, indexes |
| Foreign key relationships between tables |
| List all indexes with columns and properties |
| Search for tables and columns by name |
| Column analysis: NULLs, distinct values, min/max |
| Find duplicate rows based on columns |
Advanced Tools
Tool | Description |
| Generate ERD in Mermaid or ASCII format |
| List all constraints (PK, FK, UNIQUE, CHECK) |
Monitoring Tools
Tool | Description |
| Health check: connections, cache ratio, disk usage |
| Active locks and blocking queries |
| Find slow queries (pg_stat_statements) |
| Suggest missing indexes |
| Find unused indexes wasting space |
| Detect table/index bloat and dead tuples |
Extra Tools
Tool | Description |
| Export data to JSON or CSV |
| Export large datasets with automatic batching (streams to file) |
| Compare schema with saved snapshot |
| Generate comprehensive markdown report |
| Data quality checks: orphaned FKs, integrity |
Schema Exploration Tools
Tool | Description |
| Search schema for tables, columns, or types by keyword |
| Get compact schema overview with row counts |
| Find all tables related via foreign keys |
Supported Query Types
Query Type | Status |
Simple SELECT | ✅ |
JOINs (LEFT, RIGHT, INNER) | ✅ |
Aggregations (COUNT, SUM, AVG) | ✅ |
GROUP BY / HAVING | ✅ |
Window Functions | ✅ |
Subqueries | ✅ |
CTE (WITH clause) | ✅ |
Recursive CTE | ✅ |
UNION / INTERSECT | ✅ |
EXPLAIN ANALYZE | ✅ |
Security
Read-Only Enforcement
Multiple layers of protection ensure no data modification:
Statement Whitelist - Only
SELECT,EXPLAIN,SHOW,WITHallowedKeyword Blocklist - Blocks
INSERT,UPDATE,DELETE,DROP,ALTER,TRUNCATE,CREATE, etc.SQL Injection Prevention - Identifier validation, table existence checks
Row Limits - Configurable max rows (default: 10,000)
Query Timeout - Prevents long-running operations
Dangerous Pattern Detection - Blocks file operations, backend termination
Blocked Operations
INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE, CREATE,
GRANT, REVOKE, EXECUTE, CALL, COPY, VACUUM, REINDEX,
CLUSTER, COMMENT, SECURITY, OWNER, SET ROLE, RESETProject Structure
.db-mcp/ # Created in your project root
├── config.json # Configuration file
├── schema/
│ └── snapshot.json # Schema snapshot for AI
└── logs/
├── mcp.log # General logs
├── queries.log # Query execution logs
└── errors.log # Error logsConfiguration Options
.db-mcp/config.json:
Option 1: Using DATABASE_URL (from .env)
{
"version": "1.0.0",
"database": {
"type": "postgresql",
"envVar": "DATABASE_URL",
"schema": "public"
}
}Option 2: Individual Fields (recommended for special characters in password)
{
"version": "1.0.0",
"database": {
"type": "postgresql",
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "my>complex<password&with$special:chars",
"database": "mydb",
"ssl": "no-verify",
"schema": "public"
}
}Option 3: Individual Fields from Environment Variables
{
"version": "1.0.0",
"database": {
"type": "postgresql",
"hostEnv": "DB_HOST",
"portEnv": "DB_PORT",
"userEnv": "DB_USER",
"passwordEnv": "DB_PASSWORD",
"databaseEnv": "DB_NAME",
"ssl": "require",
"schema": "public"
}
}SSL Options
Value | Description |
| No SSL (default) |
| SSL required |
| Use SSL if available |
| SSL without certificate verification (for tunnels/self-signed) |
Full Configuration Example
{
"version": "1.0.0",
"database": {
"type": "postgresql",
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "secret",
"database": "mydb",
"ssl": "no-verify",
"schema": "public"
},
"driver": {
"query": "postgres-js",
"introspection": "drizzle"
},
"security": {
"readOnly": true,
"maxRowLimit": 10000,
"queryTimeout": 30000,
"allowedStatements": ["SELECT", "EXPLAIN", "SHOW", "WITH"]
},
"logging": {
"level": "info",
"maxFileSize": "10MB",
"maxFiles": 5
}
}Development
# Run in development mode
bun run dev
# Type check
bun run typecheck
# Lint
bun run lint
# Format
bun run formatTech Stack
Runtime: Bun - Fast JavaScript runtime
Language: TypeScript (strict mode)
MCP SDK: @modelcontextprotocol/sdk
Schema Introspection: Drizzle Kit
Database Driver: postgres.js
Validation: Zod
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE for details.
Author
Ali Burak Ozden - @ariburaco
Built with Bun and MCP for safe AI-powered database analysis.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Read-only analytics for all your apps: users, AI traffic, revenue, with the SQL behind every number.
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables read-only SQL database access for AI assistants, allowing schema exploration and safe query execution without risk of data modification.-
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to query SQL databases safely with read-only access, allowing schema discovery and SELECT queries while blocking writes and DDL operations.-
- AlicenseNot gradedqualityDmaintenanceSecurely connect AI assistants to PostgreSQL databases with read-only access, schema discovery, querying, and performance analysis tools.5 npmMIT
- AlicenseAqualityBmaintenanceEnables AI assistants to discover allowed PostgreSQL schemas, run parameterized SELECT queries, and inspect query plans safely through parser-checked read-only transactions, timeouts, row caps, and role-based access controls.4MIT