home / mcp / postgresql mcp server
Provides MCP-enabled exploration and querying of PostgreSQL databases via standardized MCP tools.
Configuration
View docs{
"mcpServers": {
"aadarshjain-postgres-mcp-server": {
"command": "python",
"args": [
"/ABOSLUTE/PATH/TO/postgres-mcp-server/server.py",
"postgresql://user:password@host:port/database"
]
}
}
}You can run a PostgreSQL MCP Server to explore and query a PostgreSQL database through a standardized MCP interface. This server connects to your PostgreSQL instance and exposes tools to list tables, inspect schemas, run read-only queries, filter records, and collect database statistics, all via MCP-compatible clients like Claude Desktop.
Start the MCP server using the PostgreSQL connection string for your database. You will then connect an MCP client to this server to perform common data discovery and querying tasks. With the tools available, you can list tables, fetch table schemas, execute read-only queries, filter records, and retrieve database statistics.
Prerequisites you need before installing:
Install required Python packages using the provided requirements file.
pip install -r requirements.txtRun the server by providing a PostgreSQL connection string. The server will listen for MCP tool requests over the local process IO.
python server.py postgresql://username:password@hostname:port/databaseTo integrate with Claude Desktop, add the following configuration to your Claude Desktop config file. This runs the server as a local process and connects to your PostgreSQL instance.
{
"mcpServers": {
"postgres": {
"command": "python",
"args": [
"/ABOSLUTE/PATH/TO/postgres-mcp-server/server.py",
"postgresql://user:password@host:port/database"
]
}
}
}Your Claude Desktop configuration file is typically located in your user directory under Claude settings. The exact path depends on your operating system.
The MCP server provides the following read-only tools to interact with your PostgreSQL database.
Only SELECT queries are allowed to prevent data modification. Connection credentials are provided at runtime in the command line and are not stored in the server. For production, consider environment variables or a secure configuration method.
If you encounter connection failures, verify your PostgreSQL connection string is correct and that the database accepts connections from your client. If the server cannot be located by the client, ensure the command path is absolute and correctly configured.
For issues or questions, you can open issues on the project page and request guidance or bug fixes.
Execute a custom SELECT SQL query and return the results.
List all tables in the current PostgreSQL database.
Get the schema definition for a specified table.
Filter database records based on specified criteria.
Get general statistics and metadata about the PostgreSQL database.