home / mcp / mcp postgresql server
Provides read-only PostgreSQL access via MCP with selectable queries, schema exploration, and common read-only utilities.
Configuration
View docs{
"mcpServers": {
"japentaca-mcp-postgres-readonly": {
"url": "https://mcp.example.com/mcp/postgresql",
"headers": {
"PORT": "3000",
"NODE_ENV": "production",
"MCP_PG_CONNSTR": "postgresql://user:pass@localhost:5432/db"
}
}
}
}You set up a dedicated MCP server that connects to your PostgreSQL database and only allows read-only SELECT queries. This keeps your data safe while letting you explore schemas, list tables, and run common read-only queries from any MCP client.
You use the MCP server by configuring a read-only connection string in your project and then starting the MCP server to serve queries to your MCP clients. The server reads the connection string from MCP_PG_CONNSTR in the root of the project you are editing. Your clients can then ask the MCP server to run prepared SELECT queries, list tables, describe tables, and perform predefined helpful queries.
Prerequisites: Node.js 18 or higher, a PostgreSQL database that your client has read access to.
git clone <repository-url>
cd postgres
npm installPlace the environment configuration in the root of the project you are editing (not in the MCP server folder). Create a .env file at the root of your project and define MCP_PG_CONNSTR with your PostgreSQL connection string.
# In the root of your project (not inside the MCP server folder)
MCP_PG_CONNSTR=postgresql://usuario:contraseña@localhost:5432/basededatosStart the MCP server from its local directory using the normal run commands shown for the server. You can use the standard start flow or development flow as needed.
# Normal start
npm start
# Development with auto-restart
npm run devIf you use Claude Desktop, point the client to the local MCP server by configuring the MCP connection in Claude’s config. Use the server as a local stdio MCP endpoint so Claude can communicate with it through the same interface you use for other MCP servers.
Runs a custom SELECT query with optional prepared statement parameters.
Lists all tables available in the connected database.
Returns detailed information about table columns.
Executes predefined useful queries such as database version, current user, current database, and table sizes.