Tim Lawrence’s Technical Program Management Portfolio

Cursor + Heroku MCP: Instant SQL Queries from Your Database

Heroku recently launched their Heroku MCP Server and one thing I've found it really useful for, is connecting to and querying databases through Cursor.

I put together a quick guide for some of my non-tech coworkers, that I thought would be useful to share out here as well.

Open Terminal (Mac)

Use the built in Mac Terminal, or install iTerm2 (Free).

Install Homebrew

''/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install Heroku CLI (via Homebrew)

'brew install heroku/brew/heroku

Install NVM (Node Virtual Manager)

Node can be a nightmare to install and manage for those that are inexperienced as different applications require different versions. NVM is Node Virtual Manager, which lets you install and switch between different versions of Node.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Install Node 22

Another version might work, but Node 22 is what I had success with alongside the Heroku MCP Server.:

  1. First install node 22, by typing the following command into your Terminal
nvm install 22
  1. Then set NVM to use version 22 by using the following command
nvm use 22

Login to the Heroku CLI

In your terminal type:

heroku login

You will get the response below asking you to login to the Heroku website:

press any key
heroku: Press any key to open up the browser to login or q to exit

You will then get a confirmation of login success!

Logged In - You can close this page and return to your CLI. It should now be logged in.

Start the Heroku MCP Server

In your terminal, type the following command:

heroku mcp:start

If the response is: Heroku MCP Server running on stdio , congratulations! You’re ready to switch to Cursor and add the Heroku MCP Server! If the response is:

Fatal error in main(): Unexpected token 'with'%

Then don’t worry, node is just being finicky! In your terminal type:

nvm use 22

It should respond with something like:

Now using node v22.21.1 (npm v10.9.4)

Use heroku mcp:start again, and you should get the running message.

Cursor: Adding the Heroku MCP Server

Issues/Troubleshooting: Dev Center - Heroku MCP Server STDIO Mode

Open Cursor, and go to settings. Select > Tools & MCP from the sidebar, then select > New MCP Server

It will open the mcp.json file in a new tab. Copy the following code into your file and hit CMD+S to save it.

{
"mcpServers": {
"heroku": {
"command": "heroku mcp:start"
}
}
}

The Heroku MCP Server should now be connected in Cursor!

Cursor: Connect to Your Database

You can now ask Cursor to connect to your database. I've had success in saving some tokens, by telling it exactly how to connect, otherwise it tries and fails a few different methods.

Connection Details

  1. First login to Heroku: heroku login
  2. Connect to database using: PGGSSENCMODE=disable psql "postgres://[credentials]" -c "[query]"
    • Get credentials with: heroku pg:credentials:url --app your-database-name

From there your options are nearly limitless! I always ask Cursor to generate a summary of the table structure as a prompt that I can save for for future use so that when I connect, it already has the context of where everything lives in the database. It can now do all the heavy lifting of creating SQL queries for me. Here an example provided by Cursor from the prompt using one of my dummy databases:

Write a query for looking administrators for a specific account, in my application.

SELECT t.display_name AS entity_name, 
       u.contact_email, 
       tr.role_label AS role_label
FROM main_table t
JOIN junction_table1 tu ON t.primary_key = tu.foreign_key1
JOIN lookup_table1 tr ON tu.foreign_key2 = tr.primary_key
JOIN user_table u ON tu.foreign_key3 = u.primary_key
WHERE t.display_name = '[ENTITY_NAME]'
  AND tr.role_label = 'administrator'
  AND tu.deleted_flag = false
ORDER BY u.contact_email;

Results

You describe the data you need in plain language and almost instantly have an executable query, cutting out the overhead of remembering schema details and join logic!

#ai #cursor #heroku #mcp #technical program management