read_queryLABSCO SUMMARY
A Postgres connection with the write switch on its own tool.
Everything an assistant needs to work a database — list the tables, read rows, read the plan — with the operations that change data in a tool you can withhold.
What it is
A Go server that puts a PostgreSQL database behind five MCP tools. Reads, writes, table creation and query plans are each a separate tool, so a client can be given the SELECT path without being given the rest.
What you get
- read_query runs a SELECT and returns rows — the read path is a tool of its own
- write_query runs INSERT, UPDATE and DELETE, so granting writes is a separate decision from granting reads
- create_table takes a CREATE TABLE statement, so schema changes happen in the same session
- list_tables lists the user-created tables, optionally filtered to one schema
- explain_query returns the execution plan for a query before you commit to running it
- Speaks stdio, Server-Sent Events and streamableHttp, so it fits local and remote client setups alike
Requirements
Go 1.23 or later and a PostgreSQL server you can reach. Connection settings come from a .env file.
Setup effort
Build from source — git clone https://github.com/leixiaotian1/pgsql-mcp-server.git
USE CASES
Answering a question straight from the database
Ask in English and get rows back. read_query takes the SELECT and returns the result, so a one-off count does not need a SQL client.
Finding out why a query is slow
explain_query returns PostgreSQL's own execution plan, so the assistant can point at the sequential scan instead of guessing at it.
Getting oriented in an unfamiliar schema
list_tables gives the user-created tables, filtered to one schema when you know where to look. The first step before any query.
Standing up a scratch table and loading it
create_table takes the CREATE TABLE statement and write_query fills the table, so a table for an experiment happens inside the conversation.
5 tools
Listed in project docs. Your client may show a different list.
write_querycreate_tablelist_tablesexplain_queryBEFORE YOU INSTALL
What to know first
Tools you get
5 tools named in the project's documentation. There is no read-only mode: write_query and create_table are limited only by your database user's permissions. explain_query expects a query that starts with EXPLAIN.
Requires
- Go 1.23 or later
- DB_PASSWORD in your environment
INSTALLATION
Connect your client
You clone and build this one yourself.
Server setup
git clone https://github.com/leixiaotian1/pgsql-mcp-server.git
cd pgsql-mcp-server
go mod download
go build -o pgsql-mcp-serverMCP Clients
Any MCP client — binary
{
"mcpServers": {
"pgsql-mcp-server": {
"command": "<YOUR_PATH_TO_PGSQL_MCP_SERVER>",
"args": [],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "postgres",
"DB_USER": "<YOUR_DB_USER>",
"DB_PASSWORD": "<YOUR_DB_PASSWORD>",
"DB_SSLMODE": "disable",
"SERVER_MODE": "stdio"
},
"disabled": false,
"autoApprove": []
}
}
}Any MCP client — HTTP
After building it, create a .env file in the pgsql-mcp-server folder with DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD and DB_SSLMODE for your database, and SERVER_MODE=streamableHttp
./pgsql-mcp-serverAdd the server to your client by its URL:
http://localhost:8088/mcp