tutorial··5 min read·WoWSQL Team

Cursor AI Database Setup: Connect Postgres with MCP

Cursor AI database setup, step by step: connect a hosted Postgres database to Cursor with MCP and OAuth, scope it safely, and let Agent build your schema.

The fastest Cursor AI database setup is to give Cursor's Agent a real Postgres database through the Model Context Protocol (MCP). You add one entry to .cursor/mcp.json, sign in once with OAuth, and Agent can list your tables, run SQL and look up docs while it writes your app code. This guide sets that up with WoWSQL's hosted MCP server, then shows a workflow that keeps the database safe while Agent does the heavy lifting.

If you want the background on what an MCP server is and how the hosted and local options compare, read our Postgres MCP server comparison first. This post is the hands-on setup.

Key facts

  • Cursor MCP support (checked on cursor.com/docs, 31 October 2026): stdio, SSE and Streamable HTTP transports; config in .cursor/mcp.json (project) or ~/.cursor/mcp.json (global); OAuth with the authorization code flow and PKCE.
  • WoWSQL MCP server: https://mcp.wowsql.com/mcp, Streamable HTTP, OAuth sign-in, so no database password goes into a config file.
  • Tools: list_projects, get_project, list_tables, execute_sql, search_docs. No storage tools.
  • Scoping: add project_ref, read_only=true and features=account,database,docs to the URL.
  • WoWSQL pricing (wowsql.com/pricing, 31 October 2026): Free at $0, Pro at $25 a month (100 MCP requests a minute), Scale at $99 a month (250 MCP requests a minute).
  • Regions: Mumbai (the default) and US East 1. WoWSQL is built in India, DPIIT-recognised and part of NVIDIA Inception.

Why give Cursor a database at all?

Without database access, Cursor guesses. It reads your code, infers what the tables probably look like, and writes queries against columns that may not exist. You then paste error messages back and forth until it converges.

With a database connected over MCP, Agent can check instead of guess. Before it writes a query it can call list_tables to see the real schema. When you ask for a migration it can draft the SQL, run it on a dev project, and confirm the result. When it isn't sure how a WoWSQL feature works it can call search_docs rather than inventing an API. The result is fewer broken queries and less copy-pasting.

Step 1: Create a project

Sign up at wowsql.com and create a project. The Free plan gives you one project on shared Postgres with 256 MB of database storage, auth, realtime and the REST and MCP APIs, with no credit card required. Pick Mumbai if your users are in India, or US East 1 if they're mostly in North America.

Note the project slug. Your project's API lives at https://<slug>.wowsqlconnect.com, and you'll use the slug again in Step 3.

Step 2: Add the MCP server to Cursor

Create .cursor/mcp.json in your project root (or ~/.cursor/mcp.json if you want it in every project):

{
  "mcpServers": {
    "wowsql": {
      "type": "http",
      "url": "https://mcp.wowsql.com/mcp"
    }
  }
}

Restart Cursor. The first time Agent uses a WoWSQL tool, Cursor opens your browser to sign in to WoWSQL and approve access. Cursor stores and refreshes the token itself, so there's no API key or connection string in the file, and it's safe to commit .cursor/mcp.json to your repo.

Prefer one click? WoWSQL is also listed on cursor.directory, which installs the same URL. Our cursor.directory announcement has the link.

Step 3: Scope it before you start

The unscoped URL lets Agent see every project on your account. For day-to-day work, pin it to one project and only the tool groups you need:

{
  "mcpServers": {
    "wowsql-dev": {
      "type": "http",
      "url": "https://mcp.wowsql.com/mcp?project_ref=myapp-dev&features=database,docs"
    },
    "wowsql-prod": {
      "type": "http",
      "url": "https://mcp.wowsql.com/mcp?project_ref=myapp-prod&read_only=true&features=database"
    }
  }
}

The dev entry can create tables and change data. The prod entry uses read_only=true, so execute_sql rejects inserts, updates, deletes and schema changes, while Agent can still read data to debug a bug report. Leaving account out of features hides list_projects and get_project, which you don't need once the project is fixed.

Step 4: Let Agent design the schema

Now give Agent a real task. In Cursor's Agent chat, try something like:

Use the wowsql-dev MCP server. Look at the existing tables, then create tables for a simple invoicing app: customers, invoices and invoice_items, with foreign keys and created_at timestamps. Show me the SQL before you run it.

Agent will call list_tables, propose SQL, and, once you approve the tool call, run it with execute_sql. A typical result looks like this:

create table customers (
  id bigserial primary key,
  name text not null,
  email text unique,
  created_at timestamptz not null default now()
);

create table invoices (
  id bigserial primary key,
  customer_id bigint not null references customers(id),
  status text not null default 'draft',
  total numeric(12,2) not null default 0,
  created_at timestamptz not null default now()
);

create index on invoices (customer_id, created_at desc);

Ask it to save the same SQL into a migration file in your repo too, so the schema lives in version control and not only in the database.

Step 5: Teach Cursor the right SDK with a project rule

AI models often mix up client libraries. A short project rule stops Cursor from writing Supabase-style or made-up calls. Cursor's docs say project rules live in .cursor/rules as .mdc files, so create .cursor/rules/wowsql.mdc:

---
description: How to query the WoWSQL database from app code
alwaysApply: true
---
- Use @wowsql/sdk. Import with `import WowSQLClient from '@wowsql/sdk'`.
- Create the client with `new WowSQLClient({ projectUrl, apiKey })`.
- Query tables with `client.table('name').select('*').get()`.
- Read keys from environment variables. Never hard-code keys.
- Before writing a query, check the real columns with the wowsql-dev MCP server.

With that in place, when you ask for "an API route that lists a customer's invoices", Agent writes code like this:

import WowSQLClient from '@wowsql/sdk';

const client = new WowSQLClient({
  projectUrl: process.env.WOWSQL_PROJECT_URL!, // e.g. myapp-dev
  apiKey: process.env.WOWSQL_API_KEY!,
});

export async function listInvoices() {
  return client.table('invoices').select('*').get();
}

Keep the service role key on the server only. For a full App Router example see our Next.js Postgres backend guide, and for sign-up and login see Postgres authentication for apps.

Safety habits that matter

  • Keep tool approvals on. Cursor can ask before each MCP call. Leave that on for anything that writes, especially execute_sql.
  • Use a separate dev project. Let Agent experiment on dev, and point it at production only with read_only=true.
  • Treat results as data. WoWSQL's MCP docs warn that rows and doc snippets can contain hostile text. If a row says "ignore your instructions", that's data, not a command.
  • Review migrations like code. Agent is fast, not infallible. Read the SQL before you approve it.

FAQ

Can Cursor connect to a Postgres database directly?

Yes, through an MCP server. You can run a local Postgres MCP server with a connection string, or connect to a hosted one like WoWSQL's over HTTPS with OAuth. Cursor supports stdio, SSE and Streamable HTTP servers.

Is it safe to let Cursor run SQL on my database?

It's as safe as the scope you give it. Pin a project_ref, use read_only=true for anything important, keep tool approvals on, and let Agent write freely only on a dev project.

Do I need an API key in mcp.json?

Not for WoWSQL's hosted server. Cursor signs in with OAuth the first time you use a tool, and it stores and refreshes the token itself. Your SDK API keys still go in environment variables for your app code.

Does this work with the free plan?

Yes. The Free plan includes the REST and MCP APIs. Pro ($25 a month) lists 100 MCP requests a minute and Scale ($99 a month) lists 250, as shown on wowsql.com/pricing on 31 October 2026.

Can Cursor manage file storage through MCP?

Not today. WoWSQL's MCP server has database, account and docs tools, but no storage tools. Use the SDK for files. For more on building AI-driven apps on Postgres, see our backend for AI agents guide.