MCP Server · npm package

AI-Powered Database Query Optimization

An MCP server that gives AI agents 8 tools to analyze, optimize, and rewrite your database queries. Explain plans, index recommendations, slow query detection, and schema inspection — all callable programmatically from any AI agent.

Get DB Query MCP — $25/mo See All 8 Tools

$25/mo. Install in 60 seconds.

8 MCP tools npm: truss-db-mcp PostgreSQL · MySQL · SQLite Claude Code · Cursor TypeScript

Bad queries silently kill your application

Slow database queries are the leading cause of application performance problems — and they're invisible until users complain. Most developers write queries that work but never check if they're optimal, missing indexes, or causing full table scans on millions of rows.

10×
Typical query speedup after adding the right index on a large table
73%
Of database performance issues trace back to missing or unused indexes
4 hrs
Average time a senior developer spends diagnosing a single slow query manually

8 MCP tools that turn AI agents into query experts

TRUSS DB Query MCP is an MCP server that AI agents use to diagnose and fix database performance problems. No manual EXPLAIN parsing. No guessing at indexes. Your agent analyzes, recommends, and rewrites — you review and apply.

analyze_query

Query Analysis

Submit any SQL query and get a detailed breakdown of what it does, potential performance issues, and estimated cost relative to table size.

get_explain_plan

Explain Plan Parsing

Run EXPLAIN or EXPLAIN ANALYZE and get a structured, human-readable breakdown of the execution plan with cost estimates and bottleneck identification.

find_slow_queries

Slow Query Detection

Scan pg_stat_statements or the slow query log to surface the top queries by execution time, call count, and total load on your database.

suggest_indexes

Index Recommendations

Analyze query patterns and table statistics to recommend which indexes to create, modify, or drop. Includes estimated read/write impact for each suggestion.

inspect_schema

Schema Inspection

Retrieve table structure, column types, constraints, existing indexes, and row counts. Gives agents full context before suggesting query optimizations.

rewrite_query

Query Rewriting

Given an inefficient query, return an optimized rewrite. Handles N+1 patterns, unnecessary subqueries, missing JOINs, and anti-patterns like SELECT *.

get_table_stats

Table Statistics

Pull vacuum stats, dead tuple counts, bloat estimates, and autovacuum schedules for any table. Diagnose hidden performance drags before they cause downtime.

check_query_safety

Query Safety Check

Before executing any write query, check for missing WHERE clauses, potential full-table deletes/updates, lock contention risks, and unsafe DDL operations.

From install to query insights in 60 seconds

TRUSS DB Query MCP is an MCP server. Install via npm, add your database connection string, and your AI agents can start analyzing queries immediately.

  1. 01

    Install and configure

    One npm command. Add your database connection string to the MCP env config. Supports PostgreSQL, MySQL, and SQLite connection strings.

  2. 02

    Add to your MCP client

    Point Claude Code, Cursor, or any MCP-compatible agent at the server. The 8 tools appear immediately in your agent's tool list.

  3. 03

    Ask your agent to optimize

    Tell your AI agent "analyze the slow queries in this app" or "suggest indexes for this query." The agent calls the MCP tools, gets structured results, and gives you actionable recommendations.

# Install npx truss-db-mcp # Claude Code / Cursor MCP config (~/.claude/mcp.json or .cursor/mcp.json) { "mcpServers": { "db-query": { "command": "npx", "args": ["truss-db-mcp"], "env": { "DATABASE_URL": "postgresql://user:pass@localhost/mydb", "TRUSS_API_KEY": "your-api-key" } } } }

Simple, flat pricing

One plan. No usage limits, no metered queries. Optimize as many queries as you want for a flat $25/mo.

Pro
$25/mo

Unlimited query analysis for one developer or team environment.

  • All 8 MCP tools
  • PostgreSQL, MySQL, SQLite
  • Unlimited query analysis
  • Explain plan parsing
  • Index recommendations
  • Slow query detection
  • Schema inspection
  • Works with Claude Code & Cursor
Get DB Query MCP

All 8 database optimization tools

  1. 01 analyze_query — Analyze any SQL query for performance issues and cost estimate
  2. 02 get_explain_plan — Run EXPLAIN ANALYZE and return a structured, readable execution plan
  3. 03 find_slow_queries — Surface top queries by execution time from pg_stat_statements or slow log
  4. 04 suggest_indexes — Recommend indexes to create, modify, or drop based on query patterns
  5. 05 inspect_schema — Retrieve table structure, column types, constraints, and existing indexes
  6. 06 rewrite_query — Return an optimized rewrite for inefficient SQL patterns
  7. 07 get_table_stats — Pull vacuum stats, bloat estimates, and autovacuum schedules
  8. 08 check_query_safety — Validate write queries for missing WHERE clauses and lock risks

Frequently asked questions

What databases does the DB Query MCP server support?

TRUSS DB Query MCP supports PostgreSQL, MySQL, and SQLite. Connect via a standard connection string in your MCP environment config. PostgreSQL support includes pg_stat_statements integration for richer slow query data.

How does AI query optimization work with MCP?

Your AI agent calls tools like analyze_query, get_explain_plan, and suggest_indexes. The MCP server connects to your database, runs EXPLAIN, analyzes execution statistics, and returns structured results the agent can reason about and act on.

Is my database data sent to any external service?

No. The MCP server runs locally in your environment. Only query metadata, execution plans, and schema information are analyzed — not your actual row data. Your database credentials stay in your local environment variables.

Does it work with Claude Code and Cursor?

Yes. TRUSS DB Query MCP is a standard MCP server that works with any MCP-compatible client: Claude Code, Claude Desktop, Cursor, VS Code Copilot, and custom agents. Add it to your mcpServers config and start using it immediately.

Stop writing slow queries

Give your AI agents the tools to find, analyze, and fix database performance issues. Install in 60 seconds.

Get DB Query MCP — $25/mo

Flat $25/mo. No usage limits. Cancel anytime.