Est.

Guide · Neon MCP

Neon MCP Server: Setup, Read-Only Mode and a Pinned Postgres Role

How to connect Claude Code, Cursor and other AI tools to Neon's hosted MCP server, what each URL parameter limits, and how to pin a Postgres role so an agent reads only what it should.

Last checked against its sources on . Part of MCP and Headless Analytics.

The Neon MCP server is Neon’s official Model Context Protocol server. Connect Claude, Cursor, VS Code or another MCP client to it and the assistant can list and create projects and branches, run SQL, describe tables, test migrations on a temporary branch, look for slow queries and search the Neon docs. It talks to the Neon API with your account’s access, and by default its SQL logs in as the database owner. Neon itself says it is meant for local development and IDE work, not production. Setting it up well comes down to a handful of URL parameters. For a Postgres database hosted somewhere else, see our Postgres MCP server guide; on Supabase, the Supabase MCP guide.

The short answer

Neon hosts the server at https://mcp.neon.tech/mcp. Add that URL to your MCP client and sign in to Neon in the browser window it opens; no API key is needed for interactive use. Neon’s CLI can write the config for you with npx neon@latest mcp. For an agent that only needs to read data, the URL worth starting from is this one:

https://mcp.neon.tech/mcp?readonly=true&projectId=<project-id>&category=querying&category=schema&roleName=mcp_reader&secrets=none

That hides every write tool and runs SQL in read-only transactions, keeps the agent to one project, loads only the SQL and schema tools, logs every query in as a Postgres role you created for it, and keeps connection strings and passwords out of tool results. Create mcp_reader first (see Pinning a Postgres role). Widen the URL when a task needs more, not before.

Connecting your AI tool

The server speaks Streamable HTTP, so any client that registers remote MCP servers can use the URL directly. The setups below use the plain URL; add the parameters from the next section to it.

Any supported client: the Neon CLI

npx neon@latest mcp

It asks where to write the config, which agents to install into and how to authenticate, then writes the entry. For CI or a headless agent, Neon documents neon mcp -y --agent <agent> --api-key <key>.

Claude Code

claude mcp add --scope project --transport http neon "https://mcp.neon.tech/mcp"

Or put it in the project’s .mcp.json:

{
  "mcpServers": {
    "Neon": {
      "type": "http",
      "url": "https://mcp.neon.tech/mcp"
    }
  }
}

Then run /mcp in Claude Code, choose the server and authenticate. Neon is also an official connector in Claude.ai and Claude Desktop.

Cursor

Add this to .cursor/mcp.json in the project, or to ~/.cursor/mcp.json for every project:

{
  "mcpServers": {
    "Neon": {
      "url": "https://mcp.neon.tech/mcp"
    }
  }
}

With an API key instead of OAuth

For a remote agent where a browser sign-in isn’t possible, send a Neon API key in the Authorizationheader. An organization’s API key limits it to that organization’s projects.

{
  "mcpServers": {
    "Neon": {
      "type": "http",
      "url": "https://mcp.neon.tech/mcp?readonly=true",
      "headers": {
        "Authorization": "Bearer <NEON_API_KEY>"
      }
    }
  }
}

Clients that only run local servers

The old local package, @neondatabase/mcp-server-neon, is deprecated, and the HTTP+SSE endpoints at /sse and /message now return 410 Gone. If a client only supports stdio, bridge to the hosted server with mcp-remote:

{
  "mcpServers": {
    "Neon": {
      "command": "npx",
      "args": ["-y", "mcp-remote@latest", "https://mcp.neon.tech/mcp"]
    }
  }
}

Client commands and config shapes change; Neon’s MCP server docs have a config generator and per-client guides for what is current.

The URL parameters that decide what an agent can do

ParameterWhat it doesExample
readonlyHides write tools (creating branches, migrations, auth changes). run_sql stays, and runs each query in a READ ONLY transactionreadonly=true
projectIdScopes every operation to one project; hides cross-project search and project management toolsprojectId=<project-id>
categoryLoads only the tool categories named (repeatable)category=querying&category=schema
roleNameEvery SQL tool logs in as this Postgres role instead of the ownerroleName=mcp_reader
secretsWhich secrets tool results show: setup (the default), all or nonesecrets=none

A few details that change how they behave:

  • With OAuth, the URL is fixed at sign-in.Parameters on the URL become the grant you approve on Neon’s authorization page, and the token keeps it. Editing the URL later doesn’t widen that token; authorize again. With the plain URL, the same page lets you untick Allow writes, pick one project, a Postgres role and the tool categories.
  • With an API key, the URL is read on every request. Anyone who can edit the config and holds the key can change or remove the parameters, so keep that file somewhere the agent can’t write.
  • Category filtering also saves context.With every category on, Neon says the server exposes well over a hundred tools, each adding its description to the model’s context. querying and schema are enough to write and run SQL.
  • Check before you connect. Neon publishes the tool list for any combination of parameters, no sign-in needed:
curl "https://mcp.neon.tech/api/list-tools?readonly=true&category=querying&category=schema"

Pinning a Postgres role

readonly=true wraps queries in a read-only transaction, but without roleName they still log in as the database owner, who can read every table. Pinning a role moves the limit into Postgres itself: every SQL tool, from run_sql to describe_table_schema and list_slow_queries, connects as that role, so its grants decide what the agent sees, and SQL that somehow got out of the transaction still has only the role’s privileges.

The catch on Neon is which roles actually limit anything. Roles created in the Neon Console or API, and roles created with the CLI or the MCP server without an access level, join neon_superuser, which can read all data. Pin one of those and nothing changes. Create the role one of two ways instead.

With the Neon CLI

neon roles create --name mcp_reader --access read_only

A read_only role gets SELECT on one database (name it with --database if the branch has more than one), on the public schema unless you pass --schema, and on tables that database’s owner owns, including ones created later. The CLI prints the role’s password once.

With SQL, for tighter grants

To give the agent some tables or columns and not others, create the role yourself. Replace the table and column names with your own:

-- As the database owner, on the branch the agent will query
CREATE ROLE mcp_reader WITH LOGIN PASSWORD '<a long random secret>';
GRANT USAGE ON SCHEMA public TO mcp_reader;
GRANT SELECT ON public.orders, public.products TO mcp_reader;

-- Tables with personal data: grant columns, not the whole table
GRANT SELECT (id, country, plan, created_at) ON public.customers TO mcp_reader;

Then add it to the URL:

https://mcp.neon.tech/mcp?readonly=true&projectId=<project-id>&roleName=mcp_reader
  • The role must be able to log in and must exist on every branch the agent queries. A role that can’t log in fails the call; the server never falls back to the owner.
  • On a pinned connection, get_connection_stringis unavailable and role passwords are hidden, so the agent never sees the role’s credentials.
  • The pin applies to SQL only. Tools that call the Neon API, such as creating branches or compare_database_schema, still act with your OAuth token or API key. Combine roleName with readonly=true and category to limit those.

The same rules for a least-privilege role apply on any Postgres host; our Postgres MCP guide covers timeouts, connection limits and what PUBLIC grants.

What the server exposes

CategoryWhat it enables
queryingrun_sql, run_sql_transaction, migrations tested on a temporary branch, explain_sql_statement, list_slow_queries, query tuning and inspect_database diagnostics
schemaget_database_tables, describe_table_schema, compare_database_schema
projectsList, create, describe and delete projects; organizations; consumption
branchesCreate, reset and delete branches; manage Postgres roles and databases
endpoints, snapshotsBranch computes; create, schedule and restore snapshots
docsSearch and read Neon’s docs and API reference
neon_auth, data_api, functions, storage, realtime, observabilityNeon’s other services: auth, the Data API, functions, object storage, realtime and logs

In read-only mode run_sql_transaction, get_connection_string and call_api are gone, and each run_sql call runs on its own. run_sql returns 100 rows by default, up to 10,000 with max_rows. The migration tools are the server’s most distinctive feature: prepare_database_migration applies a change on a temporary branch for the agent to test, and complete_database_migration applies it to the original branch. That makes schema changes safer to try; it is still a write to your main branch when it completes, so it belongs in a development project.

What the settings do not cover

Prompt injection through your own data

Rows can contain text a user wrote, and the model reads it as part of its context. An instruction hidden in a support ticket can steer the agent into reading tables it had no reason to touch. Read-only mode stops it writing; only a pinned role with narrow grants stops it reading. More in prompt injection risks when agents access live databases.

Approvals you never see

Neon keeps the destructiveHint annotation on run_sqleven in read-only mode, so clients that prompt on it still ask. But an MCP gateway, or a client that lets the model call tools from code, can run many tools in one step without a prompt. Neon’s advice for those setups is to limit the connection itself with the parameters above, because they are enforced on Neon’s side whatever client sends the request.

Data leaving the database

Every row the agent reads, and every secret a tool returns, goes to your client’s model provider and its transcript. Neon’s guidance is to keep production and personal data out of MCP sessions entirely; a branch with anonymized data is the place to point it.

IP Allow

If IP Allow is on for your project, the hosted server needs its two static addresses, 34.192.103.46 and 23.22.233.166, on the allowlist to connect.

A safe setup, in order

  1. Point the agent at a development branch or project, not the branch your app writes to.
  2. Create a role with --access read_only or your own grants, never one that joins neon_superuser.
  3. Add readonly=true, projectId, roleName, secrets=none and only the category values the task needs to the URL.
  4. Check the tool list with /api/list-tools before you connect.
  5. With OAuth, check the authorization page shows the client you expect and the grant you meant.
  6. Keep manual approval of tool calls on in your client.
  7. Keep API keys out of the repository, and use an organization key where you need one at all.

When the Neon MCP server is the wrong interface

The Neon MCP server is built for one developer working on a Neon project from an editor, and it does that well: branches to test on, migrations it can try and roll back, diagnostics on hand. It is not built for the agents inside your product, or the ones your teammates ask for business numbers. Each of those would write its own SQL against raw tables and work out its own definition of “active customer”, and a pinned role doesn’t fix that, as why Postgres role grants alone cannot scope an agent to business metrics explains.

For those agents, the pattern this site keeps returning to is a governed read surface: metrics defined once, pre-aggregated into views, and served through an MCP server that exposes those and nothing else. Start with why AI agents must not query production Postgres and exposing metrics via MCP without exposing the database.

Sources

Neon changes the server’s tools, categories and parameters often; its MCP docs and README are the reference for what is current.

Go deeper