
sql-query-mcp
MCP server giving AI clients controlled read-only access to PostgreSQL, MySQL and Hive
The repository was last updated 160 days ago and is published under MIT.
sql-query-mcp is an open-source MCP server for databases. It is available on CLI, Self-hosted and API.
- Pricing
- Open source
- Platforms
- CLI, Self-hosted, API
- What it can do
- Can change data (3 tools)
- GitHub stars
- 7
- Last commit
- Language
- Python
Similar MCP servers
About sql-query-mcp
Rather than handing an assistant raw connection strings, this server sits between an AI client and your databases and exposes schema discovery, sampling and bounded read-only queries through a fixed set of MCP tools. Connection details live in environment variables, while a JSON config file records only which connections exist and which engine each uses.
Every query is checked by sqlglot before it reaches the database. Only SELECT and WITH ... SELECT statements are accepted, comments and multi-statement input are rejected, and each call is written to an audit log. Short queries run synchronously, while longer ones can be started asynchronously, polled for paginated results and cancelled.
The project suits developers and data teams who want an assistant to understand table structure before writing SQL, without giving it write access. PostgreSQL and MySQL results can also be exported to local CSV or XLSX files, and small prepared files can be imported into existing tables.
Tools this server provides (13)
Taken from the project documentation; the running server may differ.
From the tool list in its README, going by the names, 3 of 13 tools change data; 1 name doesn't say.
From the server's own tool labels and tool names; not verified by us.
- list_connectionsName suggests: reads
- List configured connections
- list_schemasName suggests: reads
- List visible PostgreSQL schemas
- list_databasesName suggests: reads
- List visible MySQL or Hive databases
- list_tablesName suggests: reads
- List tables and views
- describe_tableName suggests: reads
- Inspect columns, keys, and indexes
- run_selectName suggests: changes
- Run short bounded read-only queries
- start_queryName suggests: changes
- Start long-running read-only queries
- get_queryName suggests: reads
- Fetch async query status and paginated results
- cancel_queryName suggests: changes
- Cancel running async queries
- explain_queryName suggests: reads
- Inspect query plans
- get_table_sampleName suggests: reads
- Fetch small table samples
- export_query_fileName suggests: reads
- Export query results to local CSV/XLSX files
- import_table_file
- Import local CSV/XLSX files
What it does
- Schema discovery tools
- List schemas, databases, tables and views, and inspect columns, keys and indexes.
- Validated read-only queries
- Queries pass SQL validation that accepts only SELECT-based statements and rejects comments and multiple statements.
- Async long-running queries
- Start, poll and cancel longer read-only queries with paginated result retrieval.
- Query plan inspection
- Run EXPLAIN on MySQL and Hive queries, with EXPLAIN ANALYZE for Hive.
- Audit logging and secret handling
- Each call is audited, and DSNs stay in environment variables instead of config files.
- Result export and file import
- Export PostgreSQL or MySQL results to CSV/XLSX and import prepared files into matching columns.
Good for
- Letting an AI assistant inspect table definitions before generating SQL
- Sampling records from production tables for quick data checks
- Running bounded analytical queries without granting write permissions
- Exporting PostgreSQL or MySQL query results to local spreadsheets
- Reviewing query plans with EXPLAIN before running heavy reports on Hive
Pricing
Open source
Free and MIT licensed; self-hosted on your own machine.
sql-query-mcp FAQ
Which databases are supported today?
PostgreSQL, MySQL and Hive are available now. SQLite, SQL Server and ClickHouse are listed as candidates and are not yet supported.
Can the AI write to my database?
Query tools are read-only and only accept SELECT and WITH ... SELECT. The only write path is importing a local CSV or XLSX file into an existing table, matching headers exactly.
How are database credentials handled?
Config files store only environment variable names. The actual DSNs are set in the MCP client's environment block.
How do I install sql-query-mcp?
It is published on PyPI as sql-query-mcp and can be installed with pipx, or launched with pipx run in the MCP client config.
Is sql-query-mcp free?
Yes. sql-query-mcp is open source, so you can use and self-host it for free.
What are the best alternatives to sql-query-mcp?
The closest alternatives to sql-query-mcp are MCP Postgres, postgres_mcp, mcp-multi-db, mysql_mcp_server and postgres-mcp.
Where this comes from
- Description: written from the project's README.


