Postgres MCP Server
Provides tools for querying PostgreSQL databases, inspecting database schemas, listing tables, and retrieving detailed table information with column definitions and constraints.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
MCP Postgres Server
A Model Context Protocol server for querying PostgreSQL databases with tools for data retrieval and schema inspection.
Setup
Prerequisites: Python 3.11+ and PostgreSQL
# Install dependencies
pip install -r requirements.txt
# Configure database connection (defaults shown)
export POSTGRES_HOST=localhost
export POSTGRES_PORT=5432
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=postgres
export POSTGRES_DB=housingRelated MCP server: PostgreSQL MCP Server
Usage
Development
Run the following command to start the server in development mode and launch the MCP Inspector:
mcp dev main.pyMCP Client Integration
You can also add the following to your MCP client configuration to use the server:
{
"mcpServers": {
"postgres": {
"command": "python",
"args": ["main.py"],
"env": {
"POSTGRES_HOST": "localhost",
"POSTGRES_PORT": "5432",
"POSTGRES_USER": "postgres",
"POSTGRES_PASSWORD": "postgres",
"POSTGRES_DB": "housing"
}
}
}
}See mcp.json for an example of how to add the server in Cursor IDE.
Available Tools
query_database- Execute SELECT queries (with SQL injection protection)get_table_schema- Get table column information and constraintslist_tables- List all database tablespostgres://schema- Access complete database schema (resource)
Comparison with Official MCP Postgres Server
This implementation differs from the official @modelcontextprotocol/server-postgres in several key ways:
Feature | This Server (Python) | Official Server (TypeScript) |
Safety | Guards against SQL injection | No protection |
Connection Pooling | ✅ Built-in (asyncpg) | ❌ Single connection |
Security
Only
SELECTstatements allowedParameterized queries supported
Environment-based configuration (no hardcoded credentials)
Next Steps
Implement auth for postgres - currently I'm still relying on env variables which doesn't seem very secure
Extend this to run on multiple databases and potentially multiple postgres instances as well
Implement table / column pruning
This server cannot be deployed
Maintenance
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Hosted PostgreSQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server providing LLMs read-only access to PostgreSQL databases for inspecting schemas and executing queries.164,787 npm27MIT
- AlicenseNot gradedqualityCmaintenanceA Model Context Protocol server that enables interaction with PostgreSQL databases to list tables, retrieve schemas, and execute read-only SQL queries.13 npmMIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.164,787 npmMIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.164,787 npmMIT