A simple Model Context Protocol (MCP) server for read-only PostgreSQL database access.
You need:
- Python 3.10+
- PostgreSQL database
- Cursor IDE
Steps:
-
Clone this repo
-
Run
pip install -r requirements.txt
-
Create
.cursor/mcp.json
with your database connection:{ "mcpServers": { "database-reader": { "command": "/absolute/path/to/python", "args": ["/absolute/path/to/database_read.py"], "env": { "PYTHONPATH": "/absolute/path/to/project", "PYTHONUNBUFFERED": "1", "MCP_SERVER_MODE": "stdio", "DATABASE_URL": "postgresql://username:password@hostname:port/database" } } } }
-
Restart Cursor
-
Ask the Agent to query your database
- Allows AI assistants to read from your database
- Provides tools for listing tables, viewing schemas, and running read-only queries
- Prevents any write operations to your database
- database_query: Run read-only SQL queries
- list_tables: List all tables in the database
- get_table_schema: Get schema for a specific table
- get_all_schemas: Get schemas for all tables at once
- SQLAlchemy requires
postgresql://
notpostgres://
in connection strings - All paths in the Cursor config must be absolute
- Restart Cursor after adding the configuration
- The .env file is not needed when using with Cursor