postgres-mcp
Provides read-only tools for exploring a PostgreSQL database schema (schemas, tables, views, columns, indexes, functions) and running guarded SELECT queries with row limits and safety validation.
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., "@postgres-mcp show me the users table schema"
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.
postgres-mcp
Universal read-only PostgreSQL MCP server for Antigravity IDE.
Exposes 8 tools to the agent so it can explore your database schema and run SELECT queries — without ever being able to mutate data.
Tools
Tool | Description |
| Server version, size, encoding, active connections |
| All non-system schemas in the database |
| Tables & views in a schema with sizes and row estimates |
| Columns, types, constraints, indexes for a table |
| First n rows (ordered by PK when available) |
| Run any read-only SELECT (guarded + row-limited) |
| EXPLAIN / EXPLAIN ANALYZE a query |
| User-defined functions and procedures in a schema |
Safety guarantees
Every SQL is validated by
guard.pybefore execution (allowlist of first keyword + blocklist of mutating patterns after comment stripping).The database session is set to
READ ONLYviaSET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY.execute_querywraps the user SQL in a subquery with a hardLIMIT(max 5000 rows).
Related MCP server: PostgreSQL MCP Server
Installation
1. Install Python dependencies
pip install "mcp[cli]>=1.0.0" "psycopg[binary]>=3.1.0"Or with uv:
uv pip install "mcp[cli]>=1.0.0" "psycopg[binary]>=3.1.0"Or install the whole project in editable mode:
pip install -e .2. Configure MCP in Antigravity IDE
Copy mcp_config.json from this repo to your global Antigravity config
directory:
~/.gemini/config/mcp_config.jsonEdit the POSTGRES_CONNECTION_STRING value:
{
"mcpServers": {
"postgres": {
"command": "python",
"args": ["-m", "postgres_mcp.server"],
"env": {
"POSTGRES_CONNECTION_STRING": "postgresql://user:password@host:5432/dbname",
"PYTHONPATH": "C:\\Users\\hdo01\\projects\\postgres-mcp\\src"
}
}
}
}If you installed via
pip install -e .you can remove thePYTHONPATHentry and replace["-m", "postgres_mcp.server"]with the installed script:"command": "postgres-mcp", "args": []
3. Reload Antigravity IDE
Navigate to Additional Options (…) → MCP Servers and confirm postgres
appears in the list with a green status indicator.
Connection string format
Standard PostgreSQL libpq URI:
postgresql://[user[:password]@][host][:port][/dbname][?param=value&...]Examples:
postgresql://admin:secret@localhost:5432/crm_dwh
postgresql://readonly_user@db.internal/analytics?sslmode=require
postgresql://user:pass@127.0.0.1:5433/mydb?connect_timeout=10Development
# Run the server directly (for debugging)
POSTGRES_CONNECTION_STRING="postgresql://..." python -m postgres_mcp.server
# Or with the MCP dev inspector
mcp dev src/postgres_mcp/server.pySecurity notes
Only ever use a read-only database role for the connection string — this is defence-in-depth on top of the application-level guard.
The
mcp_config.jsonenv block is the authoritative place for the connection string; never commit secrets to version control.Consider using a
.envfile or a secrets manager and referencing the variable name rather than the literal value.
Available Tools
8 toolsdescribe_tableA
Show columns, data types, nullability, defaults, and constraints for a table.
Args: table: Table name. schema: Schema that owns the table (default: "public").
Inputs: table (required), schema. Returns: result
execute_queryA
Execute a read-only SQL query and return results as JSON.
The query must be a SELECT (or WITH … SELECT / EXPLAIN / SHOW / TABLE / VALUES). Mutating statements are rejected before they reach the database.
Args: sql: The SQL query to execute. limit: Maximum number of rows to return (default: 500, max: 5000).
Inputs: sql (required), limit. Returns: result
explain_queryA
Run EXPLAIN (or EXPLAIN ANALYZE) on a query and return the plan.
Args: sql: The SELECT query to explain. analyze: If True, actually executes the query to get runtime stats (EXPLAIN ANALYZE). Default: False (plan only, no execution).
Inputs: sql (required), analyze. Returns: result
get_database_infoA
Return general information about the connected PostgreSQL database: version, current database, current user, encoding, timezone, and top-level statistics.
Inputs: no named parameters. Returns: result
get_table_sampleA
Return the first n rows of a table (ORDER BY primary key if available).
Args: table: Table name. schema: Schema name (default: "public"). n: Number of rows to return (default: 20, max: 500).
Inputs: table (required), n, schema. Returns: result
list_functionsB
List user-defined functions and stored procedures in schema.
Args: schema: Schema name (default: "public").
Inputs: schema. Returns: result
list_schemasA
List all schemas in the connected PostgreSQL database.
Inputs: no named parameters. Returns: result
list_tablesA
List all tables (and views) in schema.
Args: schema: PostgreSQL schema name (default: "public").
Inputs: schema. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool targets a distinct aspect of database interaction: metadata discovery (schemas, tables, columns, functions), row retrieval (sample, query), and query analysis (explain, database info). The overlap between get_table_sample and execute_query is minimal because one is a convenience for a specific table while the other accepts arbitrary read-only SQL.
All tools follow a consistent verb_noun snake_case convention, with list_* for metadata enumeration, get_* for specific retrievals, and execute_query/explain_query/describe_table for actions. There are no mixed casing styles or vague verbs.
Eight tools is well-scoped for a PostgreSQL introspection and read-only query server. Each tool covers a meaningful capability without redundancy or bloat.
The tool surface covers the full read-only lifecycle: discovering schemas, tables, columns, functions, database info, sampling data, running arbitrary SELECTs, and explaining query plans. Since execute_query permits arbitrary read-only SQL, any remaining introspection gaps can be queried directly, so there are no dead ends.
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.
Query your Postgres from ChatGPT or Claude without exposing the database or handing over credentials. Run npx boltschema connect next to your database and it dials out over HTTPS — no inbound firewall rule, no open port, works with localhost and VPC-private databases. Read-only is enforced by a SQL guard, a Postgres READ ONLY transaction, and a scoped role generated for you.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables secure read-only access to PostgreSQL databases through SELECT queries only, with tools for exploring schemas, listing tables, and executing common queries while preventing any data modification operations.MIT
- AlicenseNot gradedqualityDmaintenanceProvides secure, read-only access to PostgreSQL databases for schema inspection and data querying. It enables users to list tables, describe structures, and execute SELECT statements while strictly blocking destructive operations.1MIT
- FlicenseNot gradedqualityDmaintenanceEnables safe interaction with PostgreSQL databases through read-only queries, schema exploration, and performance analysis.-
- AlicenseNot gradedqualityDmaintenanceRead-only access to PostgreSQL databases, enabling schema inspection and safe SQL queries.MIT