In this categoryCursor ยท 26
- How to Install Cursor and Import VS Code Settings (6 Minutes)Start
- Cursor Setup Guide: From Install to Your First AI Edit
- How to Set Up Project Rules in the .cursor/rules Folder
- How to Set Up Codebase Indexing in Cursor
- How to Enforce Project Conventions with Cursor Rules
- How to Write a Team Rule That Applies Only to Certain Files
- How to Migrate a Legacy .cursorrules File to the New Rules Folder
- How to Use Cursor Rules to Guide AI Edits
- How to Set Project Rules in Cursor
- How to Add a .cursorrules File to Steer Cursor
- How to Customize Cursor Keyboard Shortcuts
- How to Edit Multiple Files at Once with Cursor Composer
- How to Use Cursor Tab Completion Effectively
- How to Edit Code Inline with Cmd+K in Cursor
- How to Add Context to Cursor Chat with @ Mentions
- How to Choose and Switch AI Models in Cursor
- How to Add Library Docs as Context with @Docs in Cursor
- How to Generate and Maintain Tests with Cursor Composer
- How to Undo a Composer Change with Checkpoints in Cursor
- How to Use Cursor Agent Mode to Build a Feature End to End
- How to Connect an MCP Server to Cursor
- How to Refactor Across Your Whole Codebase in Cursor
- How to Query Your Database from Cursor with a Postgres MCP Server
- How to Let Cursor Run Commands Automatically (and Keep It Safe)
- How to Build a Full Feature Across Frontend and Backend with Composer
- How to Debug an MCP Server That Will Not Connect in Cursor
How to Query Your Database from Cursor with a Postgres MCP Server
Wire a Postgres MCP server into Cursor so the agent can inspect your schema and run read-only queries.
Giving Cursor access to your database schema changes how it writes queries. Instead of guessing at table and column names, the agent can read the real schema through a Postgres MCP server and write SQL that actually matches your tables. This guide connects a Postgres server with a read-only connection so you can explore safely.
- Cursor with MCP support
- A reachable Postgres database and its connection string
- A read-only database user (strongly recommended)
- Node.js with npx available
Create a read-only database user
Before connecting any tool to a real database, make a user that cannot modify data. This keeps an over-eager agent from running an UPDATE or DROP against production.
CREATE USER cursor_ro WITH PASSWORD 'change_me';
GRANT CONNECT ON DATABASE appdb TO cursor_ro;
GRANT USAGE ON SCHEMA public TO cursor_ro;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO cursor_ro;Add the server to mcp.json
Add a Postgres entry to .cursor/mcp.json. Pass the connection string for the read-only user. Note the user, not the password, sits in this file, so keep the file out of version control.
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://cursor_ro:change_me@localhost:5432/appdb"
]
}
}
}.cursor/mcp.json to your .gitignore, or reference the connection string from an environment variable instead of pasting it inline.Confirm the server starts
Ask the agent about your schema
Open the agent and ask a question that requires real schema knowledge. The agent reads the table structure, then writes a query that fits your columns rather than inventing names.
Result: Cursor now writes SQL grounded in your actual schema and can answer data questions inline, all through a connection that physically cannot modify your data.
Watch related tutorials
33:42
41:18
28:05
3:12
26:54
39:10New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.