sql-copilot
Provides tools for interacting with a PostgreSQL database, including inspecting schema and table metadata, preparing query context, validating SQL, running read-only SELECT queries with limited previews, and returning write/DDL statements for manual execution rather than applying them.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@sql-copilotpreview the first 10 rows from the film table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
sql-copilot
A local MCP server for PostgreSQL. An MCP client such as Cursor or Codex starts it as a subprocess. The model calls named tools, and the server returns results over stdio. It does not open a network port.
run_select returns at most 10 preview rows and SQL you can run in your own SQL client. Direct INSERT, UPDATE, DELETE, and DDL statements are returned without being run. A SELECT does run in PostgreSQL, so use a database account with read-only access.
Arguments, result shapes, and a clone-and-test checklist are in the tool spec.
Tools
Inspect (src/sql_mcp/tools/inspect.py) reads the database structure and does not run application SQL.
Tool | What the model gets back |
| Whether PostgreSQL is reachable |
| Cached public tables, columns, and keys |
| One table, including a row estimate and indexes |
| Tables and join paths for an English question. No SQL |
Execute (src/sql_mcp/tools/execute.py) is the only place SQL is accepted.
Tool | What it does |
| Runs a |
| Classifies a statement and does not run it |
| Return the write or DDL unchanged. They do not run it |
| Reloads the in-memory schema cache |
| Recent audit lines. |
| Connection, cache age, and the latest recorded INSERT, UPDATE, or DELETE request |
Related MCP server: PostgreSQL MCP Server
Setup
Requires Python 3.11+, uv, and PostgreSQL. Query examples use the open-source DVD Rental sample. Download and restore steps are in the tool spec.
uv sync
copy .env.example .envSet DB_URL in .env. Copy .cursor/mcp.example.json to .cursor/mcp.json, then replace cwd with the folder where you cloned this project. Keep PYTHONPATH as src.
uv run python -m sql_mcp.serverRun the automated safety check from the repository root:
uv run python -m unittest discover -s tests -vThis check confirms that the SQL validator notices a DELETE hidden inside a SELECT. It does not need a running database.
Design
flowchart TD
agent[Cursor agent]
server[sql-copilot over stdio]
inspect[Inspect tools]
selectTool[run_select]
writeTool[Write and DDL tools]
cache[In-memory schema cache]
check[Parse and check names]
preview[Return at most 10 rows]
refused[Return the SQL, do not run it]
pg[(PostgreSQL)]
agent --> server
server --> inspect
server --> selectTool
server --> writeTool
inspect --> cache
cache --> pg
selectTool --> check
check --> preview
preview --> pg
writeTool --> refusedEach tool is a function registered on a FastMCP server. The MCP client speaks to that process over stdio.
schema.py loads the public schema once at startup and serves it from memory. validator.py checks SQL before a preview runs and caps the result at 10 rows. Write tools do not run write statements. logger.py appends one JSON line per call and does not store SELECT result rows.
Every database call borrows a connection from a small pool and returns it.
Current limits
Write statements are refused, including recognized writes hidden inside a
SELECT. A warning is added forUPDATEorDELETEwith no filter or an always-true filter. The server does not check every PostgreSQL function called by aSELECT; a read-only database account reduces risk but is not a complete safeguard.Schema checks use cached table and column names. They do not verify schema qualifiers and may miss table aliases or unclear column names.
One automated check covers a
DELETEhidden inside aSELECT. The setup guide also has manual checks for connecting to PostgreSQL.
Roadmap
Package the same stdio server as a Docker image so Cursor can start it with docker run -i without a local Python install. The container would still be an MCP process, not a web service.
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases using natural language queries, providing secure read-only access to database schemas and SQL translation capabilities.64 npmISC
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely interact with PostgreSQL databases through read-only operations, providing schema discovery, table inspection, and query execution capabilities with structured context awareness.MIT
- FlicenseAqualityDmaintenanceEnables AI agents to inspect and query PostgreSQL databases safely, with features like listing tables, retrieving schemas, and running read-only SQL queries.3-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases through natural language queries, schema inspection, and safe SQL execution.7 npm1ISC