home / mcp / postgres mcp server
Provides a read-only PostgreSQL query API via MCP with validation and a 10s timeout.
Configuration
View docs{
"mcpServers": {
"rathoddarshil-mcp-postgres-query-server": {
"command": "node",
"args": [
"/path/to/your/mcp-postgres-query-server/dist/index.js",
"postgresql://username:password@hostname:5432/database"
]
}
}
}You can run a read-only MCP server that lets clients query a PostgreSQL database securely and efficiently. It validates queries to ensure only SELECT statements run, enforces a 10-second timeout, and formats results as JSON for easy consumption by MCP clients like Claude Desktop.
Use your MCP client to connect to the PostgreSQL query server you run locally or on a server. The server exposes a read-only interface to your database and returns query results in JSON. You will typically configure your MCP client to use the stdio-based MCP server that you start from the project, passing the PostgreSQL connection string as an argument. Once connected, you can send SELECT queries to retrieve data from your database. The server will validate that each query is read-only and will terminate any query that runs longer than the allowed timeout.
Prerequisites you need before installing the MCP server:
Install and run the server with these steps:
# Clone the repository
git clone https://github.com/RathodDarshil/mcp-postgres-query-server.git
cd mcp-postgres-query-server
# Install dependencies
npm install
# Build the project
npm run buildConfigure Claude Desktop to automatically launch and connect to the MCP server by editing the application configuration and adding the server entry under mcpServers.
{
"mcpServers": {
"postgres-query": {
"command": "node",
"args": [
"/path/to/your/mcp-postgres-query-server/dist/index.js",
"postgresql://username:password@hostname:port/database"
]
}
}
}To apply changes to the client configuration, open Claude Desktop, adjust the config file as needed, save, and restart Claude Desktop for the changes to take effect. If you updated the MCP server code, rebuild it before restarting Claude Desktop.
Security and operation details to keep in mind include that all queries are validated to be read-only, the database connection can be configured to use SSL, and the server enforces a 10-second timeout to prevent resource exhaustion.
The MCP server is started using a stdio configuration with node and the built index script, together with a PostgreSQL connection string. The example shows how to pass the connection string as an argument to the server executable.
- All queries are validated to ensure they are read-only. - The server uses the provided database connection with SSL where available. - A timeout protects against long-running queries. - No write operations are permitted. - Credentials are provided via the connection string and are not stored in files.
Key components live in the server source and include a PostgreSQL connection pool, query validation logic, the MCP server configuration, and tool/resource definitions. To adjust behavior, you can modify the read-only query checks and timeout duration.
Executes a read-only SQL query against the configured PostgreSQL database.