How to Connect Cursor to Railway Postgres with MCP
Connect Cursor to Railway PostgreSQL via MCP. Use the public TCP proxy URL (not railway.internal), wire Synra, paste one endpoint into mcp.json. Staging vs production environments.
Railway often hosts the Postgres next to the app. Cursor is where you write migrations and API code. Without a live link, the agent invents columns for a database it never saw.
This walkthrough connects Cursor to Railway Postgres over MCP. The non-generic bits: public TCP proxy vs private railway.internal, Railway environments, and naming connections so Composer doesn't hit production by accident.
Other hosts: Connect Cursor to PostgreSQL. Neon: Connect Cursor to Neon. New to MCP? What is an MCP server.
What you can ask once it's connected
With Railway Postgres behind MCP:
- "Compare this migration to the
userstable on staging — will it fail on existing nulls?" - "How many
subscriptionsrows havestatus = 'trialing'older than 14 days?" - "Our seed assumes three orgs. What's actually in this Railway DB right now?"
- "List indexes on
orders— anything covering(org_id, created_at)?"
A one-off railway connect dump in chat goes stale the next deploy. Live queries don't.
The Railway gotcha: private vs public URL
Inside a Railway project, services talk over private networking — hostnames like Postgres.railway.internal. Your app's DATABASE_URL often points there. That's correct for the app.
Synra is not inside your Railway project. It can't resolve *.railway.internal. If you paste the private URL into Synra, the connection test fails (or hangs) and Cursor never gets tools.
You need the public path Railway exposes via TCP proxy (enabled by default on Postgres). The host looks like something.proxy.rlwy.net with a high port — not 5432 on an internal name.
| URL style | Example shape | Use with Synra? |
|-----------|---------------|-----------------|
| Private | postgresql://…@Postgres.railway.internal:5432/… | No |
| Public / TCP proxy | postgresql://…@….proxy.rlwy.net:15xxx/… | Yes |
| App variable that still embeds .railway.internal | whatever your web service references | Only if the host is public — check the hostname |
Railway bills network egress when traffic leaves via the proxy. AI query volume is usually small next to app traffic — still a reason not to let an agent hammer a huge prod table.
Step 1 — Copy the public Postgres connection string
- Open your project on railway.com
- Select the Postgres service (not your web/API service)
- Open Variables (or the Connect / networking UI for that service)
- Find the public connection string — or build one from:
PGUSER/POSTGRES_USERPGPASSWORD/POSTGRES_PASSWORDPGDATABASE- TCP proxy host + port (
RAILWAY_TCP_PROXY_DOMAIN+RAILWAY_TCP_PROXY_PORTon the Postgres service)
Final shape:
postgresql://postgres:PASSWORD@HOST.proxy.rlwy.net:PORT/railway
Confirm the host is proxy.rlwy.net (or your custom TCP hostname), not railway.internal.
Pick the environment first. Railway environments (e.g. production vs staging) each have their own Postgres variables and data. Prefer staging for Cursor. Same habit as staging-first.
Step 2 — Save it in Synra
- Sign in at mcpserver.design (7-day Solo trial is enough)
- Connections → Add new connection
- Choose PostgreSQL
- Paste the public URI
- Name it after the Railway environment —
Railway staging,Railway production replica— not a vaguePostgres - Test connection → Save
If the test fails:
- You pasted the private URL → switch to TCP proxy
- Password special characters need URL-encoding in the URI
- TCP proxy disabled on that service → enable it under the Postgres service networking settings
Credentials stay encrypted in Synra. Cursor only ever sees the MCP endpoint URL.
Step 3 — Copy the MCP endpoint
Endpoints tab → URL like:
https://app.mcpserver.design/api/mcp/aB3xY7zQ9mNpLkRv2wTs
Treat the token like a password. Rotate if it leaks.
Step 4 — Add it to Cursor
~/.cursor/mcp.json (global) or .cursor/mcp.json (per project). Don't commit the live token.
{
"mcpServers": {
"synra-railway-staging": {
"url": "https://app.mcpserver.design/api/mcp/aB3xY7zQ9mNpLkRv2wTs"
}
}
}
Name the key after the environment. Second environment later → second Synra connection + second mcp.json entry.
Older Cursor without "url" support:
{
"mcpServers": {
"synra-railway-staging": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://app.mcpserver.design/api/mcp/aB3xY7zQ9mNpLkRv2wTs"]
}
}
}
Step 5 — Restart and verify
Quit Cursor fully (Cmd+Q on Mac), reopen:
- Settings → MCP →
synra-railway-staginggreen - Tools listed:
list_tables,describe_table,query_table,execute_sql - Chat (
Cmd+L): "List the tables in this database." / "Describeusers." / "How many rows inorders?"
Then open Synra Usage and confirm the tool calls landed on the credential you named — what the audit log is for.
Habits that matter on Railway
One Synra connection per Railway environment. If you repoint the URI from staging variables to production, rename the connection (or make a new one). Don't keep calling it staging.
App DATABASE_URL ≠ what Synra needs. Private networking stays for services in the project. Synra always gets the public proxy string.
Password rotate on Railway. Update the connection in Synra and re-test. The MCP endpoint URL is unchanged unless you rotate that separately.
SELECT-only role when you can. Synra blocks writes at the gateway; a least-privilege Postgres user is the second layer. Why read-only matters.
Troubleshooting
Synra test fails, psql from your laptop works. You're probably using a different string locally (public) than you pasted (private). Recopy the proxy URL.
could not translate host name "….railway.internal". Private URL in Synra — replace with TCP proxy host.
Green in Synra, red in Cursor. Bad mcp.json (trailing comma) or stale endpoint. cat ~/.cursor/mcp.json | jq ., then recopy from Endpoints.
Empty / wrong tables. Wrong Railway environment selected when you copied variables. Fix the URI in Synra; don't keep editing Cursor for this.
Agent ignores the DB. Type @ in chat and pick synra-railway-staging once.
More: MCP troubleshooting.
Public Railway URI into Synra, endpoint into mcp.json, then ask something you already know the answer to and check the number.
7-day trial at mcpserver.design — one staging connection is enough.
Related reading:
- Connect Cursor to PostgreSQL — any Postgres host
- Connect Cursor to Neon — branch-aware Neon setup
- Connect Cursor to Supabase — Supabase credentials path
- What Your AI Query Audit Log Is For — week-one Usage habits
- Staging First — environment ladder
- Ask Cursor About Your Database — why live beats paste
- MCP Troubleshooting — tools missing
- What is an MCP Server? — protocol basics