Skip to main content

AutoDBA MCP 🚀

PyPI Version Python 3.10+ License: MIT MCP Protocol CI

Zero-database-connection static SQL analysis, automated query optimization, and execution plan diagnostics.
Powered by the Model Context Protocol (MCP) and sqlglot.

AutoDBA MCP allows AI coding assistants (Claude Desktop, Cursor, Antigravity, Windsurf) to analyze SQL queries, eliminate performance anti-patterns, synthesize zero-downtime index migration DDL, and parse execution plans—without requiring database credentials, network access, or exposing proprietary data.


⚡ Key Capabilities

  • Zero Database Connection Required: Runs 100% offline via AST parsing (sqlglot). No production DB credentials or connection strings needed.
  • Static Anti-Pattern Detection: Identifies non-SARGable column functions, Cartesian joins, cursor loops, SELECT *, leading wildcard LIKE, and unsafe locks (NOLOCK).
  • Deterministic AST Rewriter: Automatically refactors anti-patterns into high-performance SQL (e.g., converting YEAR(col) = 2026 into half-open range bounds col >= '2026-01-01' AND col < '2027-01-01').
  • Zero-Downtime Index Synthesis: Generates non-blocking DDL (WITH (ONLINE = ON) for SQL Server, CREATE INDEX CONCURRENTLY for PostgreSQL, ALGORITHM=INPLACE, LOCK=NONE for MySQL) based on query predicates and missing index requests.
  • Execution Plan Diagnostics: Parses SQL Server .sqlplan ShowPlan XML, PostgreSQL EXPLAIN (FORMAT JSON), and MySQL EXPLAIN FORMAT=JSON to pinpoint table scans, sort spills, and bottleneck operators.
  • Dialect Support: Native optimization rules for Microsoft SQL Server (T-SQL), PostgreSQL, and MySQL.

🛠️ MCP Tools

Tool Parameters Description
analyze_query sql: str, dialect: str = "tsql" Performs AST analysis, detects anti-patterns, and returns a structured Markdown diagnostic report with complexity scores.
optimize_query sql: str, dialect: str = "tsql", plan_xml_or_json: str | None Rewrites anti-patterns into optimized SQL, synthesizes zero-downtime index DDL, and simulates I/O workload reduction.
explain_execution_plan plan_content: str, dialect: str = "tsql" Parses .sqlplan XML or EXPLAIN JSON to isolate bottleneck operators and extract missing index recommendations.
list_supported_rules None Returns the catalog of built-in AST diagnostic and execution plan rules.

📚 MCP Resources & Prompts

Type URI / Name Description
Resource rules://catalog Exposes the complete diagnostic rules catalog and remediation strategies as Markdown.
Prompt optimize_query_prompt Pre-configured assistant prompt guiding a step-by-step DBA review and optimization workflow.

🚀 Quickstart & Configuration

Option 1: Claude Desktop (claude_desktop_config.json)

On macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
On Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "autodba": {
      "command": "uvx",
      "args": ["autodba-mcp"]
    }
  }
}

Option 2: Cursor (~/.cursor/mcp.json or project .cursor/mcp.json)

{
  "mcpServers": {
    "autodba": {
      "command": "uvx",
      "args": ["autodba-mcp"]
    }
  }
}

Option 3: Windsurf (~/.codeium/windsurf/mcp_config.json)

{
  "mcpServers": {
    "autodba": {
      "command": "uvx",
      "args": ["autodba-mcp"]
    }
  }
}

Option 4: Antigravity / Gemini CLI (mcp_config.json)

{
  "mcpServers": {
    "autodba": {
      "command": "uvx",
      "args": ["autodba-mcp"]
    }
  }
}

Option 5: Local Pip / Development

# Run directly with uv
uv run autodba-mcp

# Or install via pip
pip install autodba-mcp
autodba-mcp

💡 Example Usage

1. Analyzing Non-SARGable Predicates

Input:

SELECT l.LeadId, l.Email, l.CreatedDate
FROM dbo.Leads l
WHERE YEAR(l.CreatedDate) = 2026

Diagnostic Output:

# AutoDBA Query Analysis Report (TSQL)

## Overview
- **Complexity Score**: **45/100** (🟡 Moderate)
- **Tables Referenced**: `dbo.Leads`
- **Issues Detected**: 1

## Diagnostic Findings
### [NON_SARGABLE_FUNCTION] Index-Blocking Function on Column — 🔴 CRITICAL
**Finding**: Predicate applies scalar function 'YEAR' to column 'CreatedDate', blocking index seek.
```sql
YEAR(l.CreatedDate) = 2026

💡 Remediation: Rewrite predicate to isolate the column: e.g. col >= '2026-01-01' AND col < '2027-01-01'.


---

### 2. Optimizing Query & Synthesizing Index DDL

**Input:**
```sql
SELECT LeadId FROM dbo.Leads l WHERE YEAR(l.CreatedDate) = 2026

AutoDBA Output:

# AutoDBA Query Optimization Report (TSQL)

## Summary
- **Estimated Workload Improvement**: ~75%
- **Engine**: Deterministic AST Transformation
- **Semantic Verification**: ✅ Passed (All base relations and statement types preserved)
- **Anti-patterns Eliminated**: `NON_SARGABLE_FUNCTION`

## Optimized SQL Query
```sql
SELECT
  l.LeadId
FROM dbo.Leads AS l
WHERE
  l.CreatedDate >= '2026-01-01' AND l.CreatedDate < '2027-01-01'
-- Table: Leads | Rationale: Index supporting equality / range filters: CreatedDate
CREATE NONCLUSTERED INDEX [IX_AutoDBA_Leads_CreatedDate]
ON [dbo].[Leads] ([CreatedDate])
INCLUDE ([LeadId])
WITH (ONLINE = ON, DATA_COMPRESSION = PAGE);

---

## 🛡️ Security & Privacy Guarantees

- **No Remote Calls by Default**: Static analysis and deterministic rewrites execute 100% locally on your machine.
- **Zero Database Access**: AutoDBA never requires DB hostnames, ports, usernames, or passwords.
- **Sanitized Inputs**: Strips non-printable control characters and enforces AST validation before processing.

---

## 🧪 Development & Testing

```bash
# Clone the repository
git clone https://github.com/jeffreyehogg/autodba-mcp.git
cd autodba-mcp

# Create virtual environment and install in editable mode
uv venv --python 3.12
source .venv/bin/activate
uv pip install -e ".[dev]"

# Run test suite
pytest

# Code linting
ruff check .

📄 License

MIT License. See LICENSE for details.

Metadata

Release files for autodba-mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autodba-mcp 0.1.0
File Size Uploaded
autodba_mcp-0.1.0.tar.gz 119.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autodba-mcp 0.1.0
File Interpreter ABI Platform
autodba_mcp-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 169.5 kB

Release files / autodba_mcp-0.1.0.tar.gz

Download URL autodba_mcp-0.1.0.tar.gz
Size 119.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9d9913241fb36f249b9d0c62528dedcd50ddbbdbd91bd3b4aa8e7b7660b93f41
BLAKE2b-256 checksum
How to use checksums
579df15b563334c96e932d0fd3c033369b4dd078e9c5b67a6352cb2d5c6cad8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.

Transparency log

Release files / autodba_mcp-0.1.0-py3-none-any.whl

Download URL autodba_mcp-0.1.0-py3-none-any.whl
Size 49.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
77a0c2418ce006219e97a5842fddac58d4037b18d4b101deecec1b7a1304de19
BLAKE2b-256 checksum
How to use checksums
04cba6305f38fa7897528aa7ef80bd092ca9d9ffff910c82b56b22e542e5669c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page