What Claude sees when you connect your database
Connecting Claude to a database is easy now. Whichever way you do it, four questions decide how risky it is: where the database password lives, what stops a write, what the AI ends up seeing, and whether anyone can tell afterwards what it read. This page goes through each with plain SQL you can use with any tool. Portward comes in the last third.
1. The password
Section titled “1. The password”Most ways of connecting keep the password close to the AI. The archived reference Postgres server for MCP took a full connection string, password included, in the AI app’s config file (reference server). Community servers read it from an environment variable or a config file (Postgres MCP Pro, DBHub). Vendor-hosted servers replace it with a sign-in to the vendor (Supabase, Neon, PlanetScale).
The worst place for it is the chat itself. Anything typed into a conversation is sent to the AI provider and kept with the conversation.
2. What stops a write
Section titled “2. What stops a write”There are two kinds of “read-only”:
- A check in the tool. The tool inspects or wraps the SQL. These can be bypassed. The reference Postgres server
ran every query inside a
READ ONLYtransaction; Datadog Security Labs showed that a string with a second statement, starting withCOMMIT;, ended that transaction and ran a write (Datadog). The server has been archived since 2025-05-29 and its npm package is marked unmaintained. DBHub’s documentation calls its own read-only mode “a guardrail… not a permission boundary” (DBHub). - The login’s permissions. If the database login can only
SELECT, no SQL the AI writes can change anything. This is what OWASP recommends for AI tools in general: give an extension only the permissions it needs, and don’t let a read-only extension use an identity that can also write (OWASP LLM06:2025).
Use both, but rely on the second. A read-only login for PostgreSQL (GRANT, ALTER DEFAULT PRIVILEGES, ALTER ROLE):
CREATE ROLE claude_ro WITH LOGIN PASSWORD '<replace with a new password>';GRANT CONNECT ON DATABASE <your_db> TO claude_ro;GRANT USAGE ON SCHEMA <your_schema> TO claude_ro;GRANT SELECT ON ALL TABLES IN SCHEMA <your_schema> TO claude_ro; -- or name only the tables it needsALTER DEFAULT PRIVILEGES FOR ROLE <table_owner> IN SCHEMA <your_schema> GRANT SELECT ON TABLES TO claude_ro; -- tables created laterThree details from the PostgreSQL docs. ALTER DEFAULT PRIVILEGES covers only tables the named role creates later. A
password set in SQL can end up in server logs; psql’s \password avoids that
(ALTER ROLE). And a read-only transaction blocks
INSERT, UPDATE, DELETE, DDL and similar commands, but PostgreSQL calls it “a high-level notion of read-only that
does not prevent all writes to disk” (SET TRANSACTION).
ALTER ROLE claude_ro SET default_transaction_read_only = on only sets a default; a session can change it, so treat it
as a backstop, not the control.
For MySQL (GRANT):
CREATE USER 'claude_ro'@'%' IDENTIFIED BY '<replace with a new password>';GRANT SELECT ON <your_db>.* TO 'claude_ro'@'%';If the database’s name has an underscore or a percent sign in it, write it with a backslash in front
(`shop\_prod`): in a grant on a whole database MySQL reads those two characters as wildcards.
Portward’s setup form writes these scripts for you, with the login and database names you typed, for each kind of
database it connects: open Need a login that can only read? under the fields. See
Connect PostgreSQL and Connect MySQL. The form’s PostgreSQL script
leaves out ALTER DEFAULT PRIVILEGES, so a table made later isn’t readable until you grant it.
3. What the AI sees
Section titled “3. What the AI sees”A read-only login still lets the AI read everything that login can read. Whatever a query returns goes into the conversation, and from there to the AI provider under its terms.
Two things follow:
- Read access is disclosure. If the login can
SELECTfromcustomers, every column ofcustomerscan reach the model. Grant columns instead of tables (GRANT SELECT (id, region, total) ON orders TO claude_ro;), or give the login views that leave sensitive columns out. Note that a table-level grant overrides a column-level revoke (GRANT). - Data can steer the AI. In July 2025, General Analysis showed an agent using the Supabase MCP server reading a support ticket that contained instructions, then querying a secrets table and writing the result back into the ticket. The agent’s login could bypass row-level security, so “no permissions were violated” (General Analysis). Simon Willison calls the combination of private data, untrusted content and a way to send data out the “lethal trifecta” (Willison). Supabase’s own docs now warn about prompt injection and advise connecting to production only when a task needs it (Supabase). Claude’s help pages warn that a custom connector reaches a server Anthropic hasn’t verified (Claude Help Center).
The defence is the same as for disclosure: the less the login can read, the less a steered AI can leak.
4. Knowing what it read
Section titled “4. Knowing what it read”When someone asks “what did the AI see?”, most setups can’t answer. Database statement logs record SQL text, not what came back. Of the servers above, MCP Toolbox emits OpenTelemetry traces (mcp-toolbox), PlanetScale tags MCP queries so they appear in its Insights view (PlanetScale), and DBHub lists the latest requests in memory until it restarts (DBHub); none we checked keeps a lasting record a user can read of what the AI was sent. If you build your own, log the question, the SQL, the row count and a hash of the result for each call, kept apart from the rows.
5. How Portward handles the four questions
Section titled “5. How Portward handles the four questions”Portward is a Claude connector for PostgreSQL and MySQL databases on the internet. You add it to Claude as a custom connector, connect your database once in a Portward form in the chat or on a Portward web page, and ask in the chat (Portward in Claude).
- The password is typed in Portward’s form or on its setup page, never as a chat message. In the form it is sealed before it leaves, and no tool the AI can call takes a password. It is stored on your account’s engine, sealed to that engine’s own key, and is never sent to Portward’s account service.
- Writes. Portward parses each query before it runs. It must be exactly one plain
SELECTover your tables: no writes, schema changes, row locks, second statements, or functions outside a known-safe set. It then runs inside a read-only transaction and is stopped after 30 seconds. A login with administrator rights is refused when you connect; one that can write some tables is accepted with a warning, and the read-only transaction still stops any write. Use the read-only login above anyway. - What Claude sees. When you connect, you tick the columns Claude never gets; columns whose names look personal (email, phone, address and similar) are suggested, unticked, and nothing is kept back until you choose Keep these back or Send real values. A kept column is left out of the tables Claude’s queries can see, in every query. By default Claude gets each result minus kept columns, up to 200 rows; in “I send rows myself” mode it gets only the shape of a result, and you pick the rows in a panel.
- The record. Portward keeps a history of each query (the question, the SQL, the row count and a hash of the result) and keeps what Claude was sent, sealed, for 30 days; the panel shows a receipt. Apart from what Claude was sent, and the rows of your last 50 results, held sealed for 24 hours for the panel, it keeps no copy of result rows. The history of questions and SQL is kept 90 days on a hosted engine, then deleted.
What Portward doesn’t protect you from:
- Portward runs this. Portward runs the engine that reads your database. It opens your login and sees the rows it reads, so Portward can technically see what passes through it. The sealed login protects a copied disk or a backup, not against Portward as the operator. Details: signup.portward.ai/security.
- What Claude receives goes to Anthropic, like anything else in the chat. Keeping a column from Claude is how you keep it from the AI provider.
- A steered Claude can still ask for anything the login and your kept columns allow. Portward narrows what a prompt injection can reach; it doesn’t detect one.
- Internet databases only. Private, loopback and cloud-internal addresses are refused. For data only your computer reaches, use Portward on your computer.
What Portward does not protect against has the full list, with what you type into the chat and what can be worked out from the columns that are sent.