Tutorials December 28, 2024 3 min read

Setup MCP with Cursor in 5 Minutes

Step-by-step guide to connect your PostgreSQL database to Cursor's AI assistant using DataMCP's Model Context Protocol integration.

S

Sarah Kim

Developer Relations Engineer

Setup MCP with Cursor in 5 Minutes

Connect Your Database to Cursor’s AI in 5 Minutes

Tired of copy-pasting database schemas into Cursor? Let’s fix that. In this tutorial, you’ll learn how to give Cursor direct access to your PostgreSQL database schema using DataMCP’s Model Context Protocol integration.

What You’ll Achieve

By the end of this tutorial, Cursor will:

  • ✅ Know your entire database schema in real-time
  • ✅ Generate perfect queries without schema lookups
  • ✅ Create TypeScript interfaces that match your tables
  • ✅ Suggest optimal database patterns and relationships

Prerequisites

  • Cursor IDE installed
  • PostgreSQL database (local or remote)
  • Node.js 18+ installed
  • 5 minutes of your time

Step 1: Install DataMCP CLI

Open your terminal and install the DataMCP CLI:

1
npm install -g @datamcp/cli

Verify the installation:

1
datamcp --version

Step 2: Create Your DataMCP Account

Sign up for a free DataMCP account:

1
datamcp auth login

This will open your browser for authentication. The free tier includes:

  • ✅ 1 database connection
  • ✅ Real-time schema sync
  • ✅ MCP integration
  • ✅ 14-day trial of premium features

Step 3: Connect Your Database

Add your PostgreSQL database:

1
datamcp connect add postgres://username:password@host:port/database

Example Connections

Local PostgreSQL:

1
datamcp connect add postgres://postgres:password@localhost:5432/myapp

Supabase:

1
datamcp connect add postgres://postgres:[password]@db.[project].supabase.co:5432/postgres

Neon:

1
datamcp connect add postgres://[user]:[password]@[endpoint]/[dbname]?sslmode=require

Railway:

1
datamcp connect add postgres://postgres:[password]@[host]:[port]/railway

Verify Connection

Test your database connection:

1
datamcp connect test

You should see:

✅ Database connection successful
✅ Schema extraction complete
✅ Found 12 tables, 45 columns

Step 4: Configure Cursor MCP Integration

Generate the MCP configuration for Cursor:

1
datamcp setup cursor

This creates a configuration file at ~/.cursor/mcp.json with your database connection details.

Manual Configuration (Alternative)

If the automatic setup doesn’t work, create ~/.cursor/mcp.json manually:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  "mcpServers": {
    "datamcp": {
      "command": "npx",
      "args": ["@datamcp/mcp-server"],
      "env": {
        "DATAMCP_API_KEY": "your-api-key-here"
      }
    }
  }
}

Get your API key from:

1
datamcp auth whoami

Step 5: Restart Cursor

Close and restart Cursor completely for the MCP integration to take effect.

Step 6: Test the Integration

Open Cursor and start a new chat. Try these test prompts:

Test 1: Schema Exploration

Show me all the tables in my database

Cursor should list all your tables with their columns and relationships.

Test 2: Query Generation

Write a query to get all users with their most recent orders

Cursor should generate a perfect JOIN query using your actual table and column names.

Test 3: TypeScript Interface

Create a TypeScript interface for the users table

Cursor should generate an interface that exactly matches your database schema.

Troubleshooting

MCP Server Not Found

If Cursor can’t find the MCP server:

  1. Verify the configuration file exists:

    1
    
    cat ~/.cursor/mcp.json
    
  2. Check your API key:

    1
    
    datamcp auth whoami
    
  3. Test the MCP server directly:

    1
    
    npx @datamcp/mcp-server --test
    

Connection Issues

If database connection fails:

  1. Test connectivity:

    1
    
    datamcp connect test
    
  2. Check firewall settings (ensure port 5432 is accessible)

  3. Verify SSL requirements:

    1
    
    datamcp connect add "postgres://user:pass@host:5432/db?sslmode=require"
    

Schema Not Updating

If schema changes aren’t reflected:

  1. Force a schema refresh:

    1
    
    datamcp sync refresh
    
  2. Check sync status:

    1
    
    datamcp sync status
    

Advanced Configuration

Multiple Databases

Connect multiple databases:

1
2
datamcp connect add postgres://... --name production
datamcp connect add postgres://... --name staging

Switch between them in Cursor:

Use the staging database schema

Schema Filtering

Exclude certain tables or schemas:

1
2
datamcp config set exclude-tables "logs,temp_*"
datamcp config set exclude-schemas "information_schema,pg_*"

Auto-Sync Settings

Configure automatic schema synchronization:

1
2
3
4
5
# Sync every 5 minutes
datamcp config set sync-interval 300

# Enable real-time sync (premium feature)
datamcp config set realtime-sync true

What’s Next?

Now that you have Cursor connected to your database, try these advanced workflows:

1. API Development

Ask Cursor to generate complete REST endpoints with proper validation and database queries.

2. Migration Generation

Describe schema changes in natural language and let Cursor generate the migration files.

3. Test Data Creation

Generate realistic test data that respects your database constraints and relationships.

4. Performance Optimization

Ask Cursor to analyze and optimize your queries based on your actual schema and indexes.

Pro Tips

1. Be Specific

Instead of “get users”, try “get all active users with their subscription details from the last 30 days”

2. Use Natural Language

Cursor understands context better when you describe what you’re trying to achieve, not just the technical implementation.

3. Leverage Relationships

Cursor knows your foreign keys and can suggest optimal JOIN patterns automatically.

4. Ask for Explanations

Add “and explain the query” to understand the generated SQL and learn optimization techniques.

Security Note

DataMCP uses encrypted connections and doesn’t store your actual data—only schema metadata. Your database credentials are encrypted and stored securely.

For production environments, consider using read-only database users:

1
2
3
4
5
-- Create read-only user for DataMCP
CREATE USER datamcp_readonly WITH PASSWORD 'secure_password';
GRANT CONNECT ON DATABASE your_db TO datamcp_readonly;
GRANT USAGE ON SCHEMA public TO datamcp_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO datamcp_readonly;

Conclusion

You now have Cursor connected to your database with real-time schema access! This setup will save you hours of context switching and eliminate database-related coding errors.

The combination of Cursor’s AI capabilities with DataMCP’s schema intelligence creates a development experience that feels like magic.

Need Help?


Ready to supercharge your development workflow? Try DataMCP free for 14 days and experience the future of AI-assisted development.

Tags

Tutorial Cursor MCP Setup PostgreSQL AI Tools

Share

S

Sarah Kim

Developer Relations Engineer

Sarah helps developers integrate AI tools into their workflows. She's passionate about making complex technology accessible to everyone.

Related Articles

Ready to Transform Your AI Development Workflow?

Connect your database to Cursor, v0, Lovable, and other AI coding tools. Stop copy-pasting schemas and get perfect code generation.