MCP Database Performance Analyzer
An MCP server that analyzes SQL schemas, generates realistic test data, benchmarks queries, and provides optimization recommendations to improve database performance.
README
MCP Database Performance Analyzer
Autonomous MCP server for SQL schema analysis, data generation, benchmarking and optimization.
A production-ready Model Context Protocol (MCP) server that acts as an intelligent SQL performance analysis and optimization assistant. Point it at a SQL dump, and it will parse the schema, populate a database with realistic relational data at scale, benchmark queries, identify bottlenecks, explain root causes, and generate optimized SQL and indexing recommendations.
✨ Features
| Category | Capabilities |
|---|---|
| Schema Analysis | Parse SQL dumps · Detect PK/FK/indexes/views/procedures/triggers · Relationship graph · Missing FK indexes |
| Data Generation | 6 business domains · 10k–10M rows · Referential integrity · Deterministic seed |
| Query Execution | SELECT/JOIN/CTE/Window functions · Execution metrics · EXPLAIN analysis |
| Benchmarking | P50/P95/P99 latencies · QPS · Concurrent workloads · Before/after comparison |
| Optimization | Anti-pattern detection · Query rewriting · Index recommendations · Health score (0–100) |
| Reporting | JSON · Markdown · HTML · CSV · PDF · ERD diagrams |
🚀 Quick Start
Prerequisites
- Node.js 20+
- MySQL 8.0 (or use Docker)
Option 1: Docker (Recommended)
# Start MySQL + MCP server
docker compose up -d
# Wait for MySQL to be healthy
docker compose logs -f mcp-server
Option 2: Local
# Install dependencies
npm install
# Copy and configure environment
cp .env.example .env
# Edit .env with your MySQL credentials
# Build
npm run build
# Run
npm start
🔧 MCP Tools
| Tool | Description |
|---|---|
load_schema |
Parse a SQL dump file and extract the full schema model |
analyze_schema |
Analyze relationships, ERD, missing FK indexes, circular dependencies |
create_database |
Execute all DDL in dependency order and validate creation |
generate_test_data |
Preview generated data without inserting (dry run) |
populate_database |
Insert realistic relational data at specified scale |
execute_query |
Execute a SQL query with metrics capture |
benchmark_query |
Benchmark a query with P50/P95/P99 and QPS |
benchmark_database |
Run a mixed workload simulation |
analyze_execution_plan |
EXPLAIN + EXPLAIN ANALYZE with insights |
detect_slow_queries |
Classify queries and detect root causes |
recommend_indexes |
Detect missing, duplicate, unused, redundant indexes |
optimize_query |
Anti-pattern detection + query rewriting |
compare_queries |
Side-by-side benchmark with improvement % |
generate_report |
Full report in JSON/Markdown/HTML/CSV/PDF |
reset_database |
Truncate or recreate the database |
📋 Example Workflow
1. load_schema(sql: "<content of dump.sql>")
2. analyze_schema()
3. create_database()
4. populate_database(domain: "ecommerce", datasetSize: "100k")
5. benchmark_query(sql: "SELECT * FROM orders JOIN customers ON ...")
6. analyze_execution_plan(sql: "...")
7. detect_slow_queries(queries: [...])
8. recommend_indexes()
9. optimize_query(sql: "...")
10. generate_report(formats: ["html", "pdf"])
🗄 Database Support
| Database | Status |
|---|---|
| MySQL 8.0 | ✅ Full support (primary) |
| PostgreSQL | 🔶 Stub (core ops work, advanced metrics pending) |
| SQLite | ✅ Full support (used for tests) |
| SQL Server | 📋 Planned |
🏢 Business Domains
The data generator supports 6 business domain profiles:
- ecommerce — customers, products, orders, payments, reviews
- erp — suppliers, purchase orders, inventory, warehouses, accounts
- crm — contacts, leads, deals, activities, campaigns
- hospital — patients, doctors, appointments, prescriptions, diagnoses
- banking — accounts, transactions, loans, cards, branches
- hr — employees, departments, positions, payroll, performance reviews
🔍 Optimization Detectors
| Anti-Pattern | Detection | Auto-Fix |
|---|---|---|
| SELECT * | ✅ | ✅ |
| Large OFFSET pagination | ✅ | ✅ |
| Non-sargable predicates | ✅ | ✅ |
| Leading wildcard LIKE | ✅ | — |
| Implicit type cast | ✅ | ✅ |
| Missing FK indexes | ✅ | ✅ |
| Duplicate indexes | ✅ | ✅ |
| Unused indexes | ✅ | ✅ |
| Full table scans | ✅ | — |
| Filesort | ✅ | — |
| Temporary tables | ✅ | — |
📊 Health Score
The database health score (0–100, Grade A–F) is computed from weighted categories:
| Category | Weight |
|---|---|
| Index Strategy | 30% |
| Schema Design | 25% |
| Query Efficiency | 25% |
| Data Distribution | 10% |
| Security | 10% |
🧪 Testing
# Unit tests (no external DB required)
npm test
# Integration tests (requires MySQL or use SQLite path)
npm run test:integration
# Type check
npm run typecheck
📁 Project Structure
src/
├── index.ts # Entry point
├── server.ts # MCP server + adapter setup
├── config/ # Typed configuration
├── adapters/ # Database adapters (MySQL, PostgreSQL, SQLite)
├── modules/
│ ├── sql-parser/ # SQL DDL/DML parser
│ ├── schema-analyzer/ # Relationship graph, orphan/cycle detection
│ ├── erd-generator/ # Mermaid ERD generation
│ ├── database-creator/ # DDL execution in dependency order
│ ├── data-generator/ # Faker-based relational data generation
│ ├── bulk-loader/ # Batched INSERT with concurrency control
│ ├── query-executor/ # Query execution with metrics
│ ├── benchmark-engine/ # P50/P95/P99 latency benchmarking
│ ├── explain-analyzer/ # EXPLAIN plan parsing and insights
│ ├── slow-query-detector/ # Query classification
│ ├── index-analyzer/ # Missing/duplicate/unused index detection
│ ├── optimization-engine/ # Anti-patterns, query rewriting, health score
│ └── report-generator/ # JSON/MD/HTML/CSV/PDF rendering
├── tools/ # All 15 MCP tool handlers
├── types/ # Shared TypeScript interfaces
└── utils/ # Logger, progress reporter, retry
🌐 Claude Desktop Integration
Add to your claude_desktop_config.json:
{
"mcpServers": {
"db-optimizer": {
"command": "node",
"args": ["/path/to/database-benchmark/dist/index.js"],
"env": {
"DB_ADAPTER": "mysql",
"DB_HOST": "127.0.0.1",
"DB_PORT": "3306",
"DB_USER": "root",
"DB_PASSWORD": "root",
"DB_NAME": "mcp_benchmark"
}
}
}
}
🤝 Contributing
Contributions are welcome! Please see our Contributing Guide for guidelines on code style, testing, and submitting pull requests.
📄 License
This project is licensed under the terms of the MIT License.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。