Skip to content
Keepware Subscribe

Give Claude Code read-only access to a production database

Let Claude Code or Cursor query production safely with QuerentDB: a read-only database account, an MCP token limited to prod and read-only, and a protected environment.

Part 12 of 13· Nov 11, 2026·3 min read

To let Claude Code, Cursor or another AI agent look at a production database without being able to change it, connect it through QuerentDB, a desktop database client by Keepware, and stack four limits:

  1. The database account. The connection’s Read-only account is a database user that can only SELECT; queries run on it, so the database itself refuses writes.
  2. The token. An MCP token with Custom access to prod only and Read-only on can’t write anywhere and can’t see your other environments.
  3. The environment. A Protected environment makes every write ask for approval on your screen, whatever a token allows.
  4. The AI policy. Schema + data lets the agent run read-only queries; Schema only limits it to tables and columns.

The agent never sees the database password or the SSH tunnel: it sends a statement to QuerentDB on your computer, and gets rows back.

Step 1: Give the connection a read-only database account

In the connection’s sheet, fill in the Read-only account with a database user that only has read privileges, such as:

-- MySQL
CREATE USER 'reader'@'%' IDENTIFIED BY '…';
GRANT SELECT ON acme_store.* TO 'reader'@'%';

-- PostgreSQL
CREATE ROLE reader LOGIN PASSWORD '…';
GRANT USAGE ON SCHEMA public TO reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO reader;

Everything the agent runs uses this account. Leave the Read-write account empty if nobody should write through this connection at all.

Step 2: Put the connection in a protected environment

Keep production connections in their own environment, such as prod, with Protected on (and Require TLS if the database is reachable over a network you don’t control). Choose its AI policy: Schema + data to let agents run read-only queries, or Schema only to let them see the structure but no rows. See Environments.

Step 3: Create a token limited to prod, read-only

In Settings → MCP & CLI, choose New token:

  • Name: what it’s for, such as Claude Code (prod, read-only).
  • Access: Custom, then tick only prod.
  • Read-only: on.
  • Expires: as short as is practical.

A new personal token: Custom access with only prod ticked, and Read-only on

Choose Create, copy the token (it’s shown once), and add QuerentDB to the agent with it; see Use QuerentDB as an MCP server for Claude Code, Cursor and VS Code.

The token in the list: only prod, read-only

What does the agent see now?

Through this token, the agent sees one environment, with read access:

{
  "workspace": "Personal",
  "environments": [
    {
      "id": "27be4801-af01-443e-aea6-2ac0c9d94122",
      "name": "prod",
      "access": "read",
      "protected": true,
      "aiPolicy": "full"
    }
  ],
  "summary": "1 environment"
}

It can query prod. QuerentDB adds a LIMIT when there isn’t one (50 rows by default, 200 at most) and runs the statement on the read-only account:

{
  "results": [
    {
      "statement": "SELECT status, COUNT(*) AS orders FROM orders GROUP BY status\nLIMIT 50",
      "elapsedMs": 1,
      "columns": [
        "status",
        "orders"
      ],
      "rows": [
        [
          "pending",
          44
        ],
        [
          "paid",
          181
        ],
        [
          "shipped",
          157
        ],
        [
          "refunded",
          18
        ]
      ],
      "rowCount": 4,
      "truncated": false
    }
  ],
  "account": "read",
  "summary": "4 rows · 8 ms"
}

A write is refused before it reaches the database:

{
  "error": {
    "code": "read_only",
    "message": "You have read-only access in prod: writes aren't allowed"
  }
}

And your other environments don’t exist as far as it’s concerned:

{
  "error": {
    "code": "not_found",
    "message": "No connection named dev/acme-mysql (see list_connections)"
  }
}

FAQ

Why not just give the agent a read-only database user directly?

You could, but then the agent holds the password, connects from wherever it runs, and you can’t narrow or revoke its access without changing the database. Through QuerentDB, the password stays on your computer, the token can be revoked in one click, results are capped, and in a team every query can be in the audit log.

Can I let the agent propose changes but not run them?

Yes: leave Read-only off and Approve writes on. Every write the agent sends then waits for Allow once on your screen, showing the statement and about how many rows it affects, and in a protected environment you also type its name.

Does this work with Cursor and VS Code?

Yes. The token and the limits are the same for every MCP client; only the configuration snippet differs.