A generic Model Context Protocol (MCP) server for PostgreSQL, allowing AI agents to inspect and query PostgreSQL databases safely.
list_tables: List all tables in thepublicschema.get_schema: Get the schema (columns, types, nullability) of a specific table.run_query: Run a read-only SQL query (onlySELECT/WITHallowed) with a maximum limit of 100 rows to avoid large responses.
- Python 3.13+
- uv
- PostgreSQL database
You can run this directly using uvx or uv run if you clone the repository.
This server requires the DATABASE_URL environment variable to be set.
Example connection string:
postgres://user:password@localhost:5432/mydatabase
DATABASE_URL="postgresql://postgres:poggerpogger@localhost:5432/boxboxWeb" uv run main.pyAdd the following to your MCP client configuration (e.g., Claude Desktop's claude_desktop_config.json):
{
"mcpServers": {
"postgres": {
"command": "uv",
"args": [
"run",
"/path/to/2025postgresqlmcp/main.py"
],
"env": {
"DATABASE_URL": "postgres://user:password@localhost:5432/mydatabase"
}
}
}
}