A Model Context Protocol (MCP) server that provides tools for interacting with a PostgreSQL database. It enables AI assistants to execute SQL
Pgsql MCP server exists for a simple reason — assistants are far more useful when they can act on Pgsql directly instead of describing what you should do. A Model Context Protocol (MCP) server that provides tools for interacting with a PostgreSQL database. It enables AI assistants to execute SQL queries, explain statements, create tables, and list database tables via the MCP protocol.
Once Pgsql is connected, these are the calls the assistant has available:
read_query — Executes a SELECT SQL querywrite_query — Executes an INSERT, UPDATE, or DELETE SQL querycreate_table — Executes a CREATE TABLE SQL statementlist_tables — Lists all user-created tables in the databaseexplain_query — Returns the execution plan for a given SQL queryPrerequisites — The Prerequisites tool exposed by this serverInstallation — 1. Clone the repository: bash git clone https://github.com/leixiaotian1/pgsql-mcp-server.git cd pgsql-mcp-serverstdio — The server communicates over standard input and output. This is the default mode and is ideal for local testing or direct integration withstreamableHttp — The server uses the Streamable HTTP transport, a more modern and flexible HTTP-based transport for MCPSetup follows the usual MCP pattern — install or clone the server, register it in your client's configuration file, restart the client. The configuration blocks on this page cover the common clients.
You will need 7 environment variables: DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD, DB_SSLMODE, SERVER_MODE. Keep credentials in your client's env block or a secrets manager rather than in a file you might commit.
Plenty of database access servers cover similar ground. The differences that matter in practice are scope of access and how much setup stands between you and a working tool call. Pgsql's toolset — read_query, write_query, create_table and 6 more — is a fair guide to whether it matches your workflow. It is maintained by leixiaotian1; worth a glance at recent repository activity before you build anything load-bearing on it.
We check each listing at SyncDev against the project's documentation before it goes live — if something here drifts out of date, it is a bug worth reporting.
| Tool | What it does |
|---|---|
| read_query | Executes a SELECT SQL query. |
| write_query | Executes an INSERT, UPDATE, or DELETE SQL query. |
| create_table | Executes a CREATE TABLE SQL statement. |
| list_tables | Lists all user-created tables in the database. |
| explain_query | Returns the execution plan for a given SQL query. |
| Prerequisites | The Prerequisites tool exposed by this server. |
| Installation | 1. Clone the repository: bash git clone https://github.com/leixiaotian1/pgsql-mcp-server.git cd pgsql-mcp-server |
| stdio | The server communicates over standard input and output. This is the default mode and is ideal for local testing or direct integration with command-line-based MCP clients. |
| streamableHttp | The server uses the Streamable HTTP transport, a more modern and flexible HTTP-based transport for MCP. |
{
"mcpServers": {
"pgsql-mcp-server": {
"command": "/path/to/pgsql-mcp-server",
"args": [],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "postgres",
"DB_USER": "your_username",
"DB_PASSWORD": "your_password",
"DB_SSLMODE": "disable",
"SERVER_MODE": "stdio"
},
"disabled": false,
"autoApprove": []
}
}
}Configuration as documented by the project. Restart the client after saving.
| Variable | Description | Required |
|---|---|---|
| DB_HOST | Endpoint or connection string the server talks to. | Optional |
| DB_PORT | Configuration value read at startup. | Optional |
| DB_NAME | Configuration value read at startup. | Optional |
| DB_USER | Configuration value read at startup. | Optional |
| DB_PASSWORD | Configuration value read at startup. | Optional |
| DB_SSLMODE | Configuration value read at startup. | Optional |
| SERVER_MODE | Configuration value read at startup. | Optional |
Read-only SQL access to Postgres — let your assistant inspect schemas and answer questions from real data.
Manage your whole Supabase project in conversation — database, auth, storage, Edge Functions and branches.
Query, modify and analyse local SQLite databases in conversation — the fastest way to chat with a data file.
Metabase ships its own MCP endpoint — search your BI content, build and run queries, and save questions and dashboards without leaving the chat.
Official MongoDB server covering data, schemas and Atlas management — from find queries to spinning up clusters.
Serverless Postgres with database branching — point your assistant at Neon and let it work on disposable copies.