SQL Query MCP logo

SQL Query MCP

by andyWang1688

Connects AI clients to PostgreSQL, MySQL, and Hive for schema discovery, bounded read-only SQL, query plans, and controlled file exchange.

Install SQL Query MCP

Pick your client, then add it in one click or paste the config.

STDIOPython
~/Library/Application Support/Claude/claude_desktop_config.json
claude_desktop_config.json
{
  "mcpServers": {
    "andywang1688-sql-query-mcp": {
      "command": "pipx",
      "args": [
        "run",
        "sql-query-mcp",
        "sql-query-mcp"
      ],
      "env": {
        "SQL_QUERY_MCP_CONFIG": "YOUR_VALUE_HERE"
      }
    }
  }
}

Settings → Developer → Edit Config, merge this into mcpServers, then fully quit and reopen Claude Desktop.

Values are written into the snippet above so you can paste it as is. They never leave your browser.

We couldn’t confirm it starts correctly

The install command didn't complete successfully in our automated test.

pipx run sql-query-mcp sql-query-mcp

Process exited before answering initialize.

This is an experimental automated check and can have false negatives — missing environment variables, a slow cold install, etc. It doesn’t necessarily mean something’s wrong. Last checked .

Overview

andyWang1688/sql-query-mcp MCP server exposes PostgreSQL, MySQL, and Hive databases through controlled MCP tools for discovery, sampling, read-only queries, asynchronous execution, and query-plan inspection. It reads database DSNs from environment variables while keeping connection definitions, namespace handling, SQL validation, and audit logging on the server side. PostgreSQL and MySQL results can be exported to local CSV or XLSX files, and prepared CSV/XLSX files can be imported into existing tables. Reach for it when an AI client needs database context and bounded SQL access without granting unrestricted SQL execution.

Use cases

  • Inspect database schemas before generating SQL
  • Run bounded read-only queries against configured databases
  • Review query plans for PostgreSQL, MySQL, or Hive
  • Export PostgreSQL or MySQL results to CSV or XLSX
  • Import prepared CSV/XLSX files into existing tables

Key features

  • PostgreSQL, MySQL, and Hive support
  • Schema, database, table, and sample discovery
  • Validated read-only SQL execution
  • Asynchronous query status, pagination, and cancellation
  • Query-plan inspection
  • Controlled CSV/XLSX export and import

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

11/11 checks healthy over the last 105d

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars7Stargazers on the source repository.
Last commit5mo agoMost recent push to the default branch.
Install checkInconclusiveInstall command did not finish in our automated test.
Directory activity7 viewsConfig copies, upvotes, and views on AllMCPs.

How SQL Query MCP works

What the andyWang1688/sql-query-mcp MCP server does

andyWang1688/sql-query-mcp MCP server gives an MCP client a controlled interface to configured PostgreSQL, MySQL, and Hive connections. It supports database structure discovery, table and column inspection, small data samples, read-only SQL, asynchronous query handling, and query-plan inspection. PostgreSQL uses schemas as namespaces; MySQL and Hive use databases.

The server also provides limited file exchange. PostgreSQL and MySQL query results can be written to local CSV or XLSX files. CSV/XLSX files can be imported into existing tables when their headers match table columns exactly. The import operation is the only database write path described by the project.

How it works

Connections are declared in a JSON configuration file. Each connection identifies its engine, connection ID, namespace defaults, and the name of an environment variable containing the real DSN. This keeps credentials out of the configuration file. The MCP client supplies SQL_QUERY_MCP_CONFIG and the DSN variables in its environment when starting the process.

SQL passes through sqlglot validation before execution. Query tools accept only SELECT statements and WITH ... SELECT statements; comments and multiple statements are rejected. Use run_select for short, bounded work. For longer read-only operations, start_query begins execution, get_query retrieves status and paginated results, and cancel_query stops a running query. Calls are recorded in an audit log.

Setup and configuration

The project documents two PyPI-based startup modes. Install the command with pipx install sql-query-mcp, then start sql-query-mcp, or let an MCP client launch it with pipx run --spec sql-query-mcp sql-query-mcp. Set SQL_QUERY_MCP_CONFIG to the connections file, such as a file under ~/.config/sql-query-mcp, rather than relying on the source-checkout default path.

Configuration settings can define default and maximum result limits plus an audit-log path. Each connection needs an explicit engine and a dsn_env entry. PostgreSQL connections may specify default_schema; MySQL and Hive connections may specify default_database. The README includes examples for PostgreSQL, MySQL, and Hive DSNs, but the actual credential-bearing values must be supplied by the operator.

Tools and capabilities

The documented tool set includes:

  • Listing configured connections, schemas, databases, tables, and views.
  • Describing table columns, keys, and indexes.
  • Running bounded read-only queries and retrieving table samples.
  • Starting, paging through, and cancelling asynchronous read-only queries.
  • Inspecting plans with EXPLAIN; Hive also supports EXPLAIN ANALYZE through the plan tool.
  • Exporting PostgreSQL and MySQL results to local CSV/XLSX files.
  • Importing local CSV/XLSX data into existing tables.

Limitations and notes

SQLite, SQL Server, and ClickHouse are listed as candidates and are not supported yet. Hive does not support query-result export. Hive file imports are intended for small files and reject inputs with more than 1,000 data rows; row-by-row insertion can also exceed an MCP client timeout. Large exports may face the same timeout issue because export is synchronous, even though rows are processed in batches.

Files are written to or read from the machine running the MCP server, not necessarily the machine displaying the AI client. Imports do not accept raw SQL and only insert file fields whose headers exactly match existing columns. The andyWang1688/sql-query-mcp MCP server therefore fits controlled database inspection and bounded data workflows better than unrestricted administration or bulk-loading operations.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about SQL Query MCP

Install it with `pipx install sql-query-mcp`, or use managed launch mode with `pipx run --spec sql-query-mcp sql-query-mcp`.

PostgreSQL, MySQL, and Hive are supported. SQLite, SQL Server, and ClickHouse are listed as unsupported candidates.

Query tools accept only read-only `SELECT` and `WITH ... SELECT` statements. The documented write path is importing CSV/XLSX data into an existing table.

Put DSNs in environment variables and reference those variable names with `dsn_env` in the JSON connection configuration. Set `SQL_QUERY_MCP_CONFIG` to the configuration file path.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewSQL Query MCP AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/andywang1688-sql-query-mcp?style=directory)](https://allmcps.com/mcp/andywang1688-sql-query-mcp)
HTML Embed
<a href="https://allmcps.com/mcp/andywang1688-sql-query-mcp"><img src="https://allmcps.com/api/badge/andywang1688-sql-query-mcp?style=directory" alt="SQL Query MCP on AllMCPs" /></a>