Skip to content
GitHub (opens in a new tab)

Databases · MCP Firewall integration

Let AI read PostgreSQL. Review changes before they run.

Put PostgreSQL access behind GateRook’s MCP Firewall. This local walkthrough shows how to scope a database connection, keep its password in GateRook, run read queries, approve one change, and trace the requests and results in Activity.

Step-by-step walkthrough

Control AI queries to PostgreSQL with GateRook’s MCP Firewall

GateRook’s MCP Firewall lets an AI app inspect and query PostgreSQL while keeping database credentials encrypted in GateRook. You choose which endpoint exposes the connection, which tools can read immediately, and which actions need your approval. Activity then shows what was requested, why it was allowed, and what happened.

This walkthrough connects a local PostgreSQL container to the showcase endpoint, reads a small orders table, approves one update, and verifies the change in both PostgreSQL and GateRook's audit log. It uses GateRook 0.7.0 and PostgreSQL 16.13. All customer names and orders are fictional.

New to GateRook? Set up your endpoint and AI app first.

1. Start a local PostgreSQL server

Start Docker Desktop and keep GateRook running. The example assumes that a development endpoint named showcase already exists and that your AI app is connected to it. In the screenshots, that app is Codex.

Run the following in a terminal. The container publishes PostgreSQL only on the computer's loopback interface, at 127.0.0.1:15432; it does not publish a database port on your LAN. Use a different container name or port if either is already occupied.

Shell commands
export POSTGRES_PASSWORD="$(openssl rand -hex 24)"

docker run -d \
  --name gaterook-postgres-showcase \
  -p 127.0.0.1:15432:5432 \
  -e POSTGRES_PASSWORD \
  -e POSTGRES_DB=gaterook_demo \
  --health-cmd 'pg_isready -U postgres -d gaterook_demo' \
  --health-interval 2s \
  --health-timeout 3s \
  --health-retries 30 \
  postgres:16.13

unset POSTGRES_PASSWORD

docker inspect --format '{{.State.Health.Status}}' \
  gaterook-postgres-showcase

Wait until the health check says healthy. Then create the sample table and a separate database login:

Shell commands
docker exec -i gaterook-postgres-showcase \
  psql -U postgres -d gaterook_demo -v ON_ERROR_STOP=1 <<'SQL'
CREATE ROLE demo_agent LOGIN PASSWORD 'local-demo-only';

CREATE TABLE public.orders (
    id integer PRIMARY KEY,
    customer_name text NOT NULL,
    status text NOT NULL
        CHECK (status IN ('pending', 'paid', 'shipped')),
    total numeric(10,2) NOT NULL
);

INSERT INTO public.orders VALUES
    (1001, 'Avery Stone', 'pending', 129.90),
    (1002, 'Morgan Reed', 'paid', 89.00),
    (1003, 'Riley Chen', 'pending', 249.00),
    (1004, 'Jordan Lee', 'shipped', 49.50);

GRANT CONNECT ON DATABASE gaterook_demo TO demo_agent;
GRANT USAGE ON SCHEMA public TO demo_agent;
GRANT SELECT, UPDATE ON public.orders TO demo_agent;
SQL

local-demo-only is a public, disposable tutorial password. Use it only for this local fixture. GateRook will connect as demo_agent, not as the PostgreSQL administrator. The explicit table grants allow SELECT and UPDATE on public.orders; they do not grant INSERT, DELETE, or ownership. UPDATE is included so that the approval flow can be demonstrated.

2. Choose the PostgreSQL connector

In GateRook, open Connections and select Add connection. The list below is filtered to keep unrelated connections out of view; filtering is not required to add a connection.

Connections with the Add connection button and unrelated connections filtered out.
Connections with the Add connection button and unrelated connections filtered out.

Select PostgreSQL, then Continue. Its four built-in tools cover schema discovery, table descriptions, read queries, and changes that require approval.

The Add connection wizard with PostgreSQL selected.
The Add connection wizard with PostgreSQL selected.

3. Enter the server and credentials

Fill in the connection fields:

FieldValue
Namepostgres-demo
Host127.0.0.1
Port15432
Secret sourceEncrypted here
Userdemo_agent
Passwordlocal-demo-only
EnvironmentDEV Development

The name is a slug used in tool calls and Activity filters. Choose it before saving: existing calls and policies refer to it, so the saved connection cannot simply be renamed.

GateRook connects from the computer running its core. Here, the host and port point to the container's published port. Encrypted here stores the credential encrypted with GateRook's master key. The database password is not part of the SQL tool arguments sent by the AI app.

Connection name, loopback address, port, and encrypted credential storage.
Connection name, loopback address, port, and encrypted credential storage.

4. Configure transport and schema access

Expand Advanced and set:

FieldValueReason
SSL modeOff (disable)This disposable container has no TLS listener and is published only on loopback.
Schema allowlistpublicLimit this connection to the tutorial schema. Add the value as a chip.
Default schemapublicResolve unqualified table names in this schema.
Discovery databasegaterook_demoUse the tutorial database when loading the database list.

Leave the other advanced fields at their defaults. For a remote database, use the default Verify the CA and host name (verify-full) with a correctly configured TLS server; provide its CA certificate when it uses a private CA. The local tutorial's SSL setting is specific to this container.

Advanced PostgreSQL settings with the public schema allowlist and gaterook_demo discovery database.
Advanced PostgreSQL settings with the public schema allowlist and gaterook_demo discovery database.

5. Select the database

Select Load databases and tick only gaterook_demo. Leave postgres unchecked. A database appearing in the discovery list does not automatically make it available through the saved connection.

Keep DEV Development selected. Its description is explicit: mutations still wait for approval. If you change the server, credentials, or transport, reload the database list before continuing.

Masked password, gaterook_demo selected, postgres unchecked, and the DEV environment.
Masked password, gaterook_demo selected, postgres unchecked, and the DEV environment.

6. Test the connection

Select Continue to open the test step. GateRook connects with the values you entered and displays the server version, connection time, and a permissions summary.

The example reports Connected · PostgreSQL 16.13 and detects that the user can read and write. The write summary is broad: the database grants created above remain the authority for which operations the role can actually perform. In this fixture, the role has only SELECT and UPDATE on the orders table.

For an analytical connection that never needs writes, use a database role with only the necessary read privileges. Here, continue with the tutorial role so that you can review an update later.

A successful PostgreSQL connection test and the detected permissions summary.
A successful PostgreSQL connection test and the detected permissions summary.

7. Add the connection to showcase

Continue to Add to endpoint. Untick default if the wizard selected it, and tick only showcase. This controls which AI apps can use the new connection: apps connected to other endpoints do not gain its tools from this selection.

Review the proposed modes, then select Save connection:

ToolMode in this walkthroughPurpose
sql_list_schemasRead onlyDiscover accessible schemas and tables.
sql_describe_tableRead onlyInspect columns, keys, indexes, and constraints.
sql_queryRead onlyExecute a validated read query.
sql_executeApprovalRequest a change for a person to review.
Only showcase selected as the destination endpoint; an unrelated endpoint name is redacted.
Only showcase selected as the destination endpoint; an unrelated endpoint name is redacted.

After saving, the connection page shows Healthy, 1 endpoint, and 4 tools on showcase. The saved password is represented by an encrypted version, rather than a readable value.

The saved postgres-demo connection, healthy status, and its use by showcase.
The saved postgres-demo connection, healthy status, and its use by showcase.

8. Understand the request path

Open Endpoints → showcase. The connection diagram shows the path from Codex through the endpoint to postgres-demo.

The showcase endpoint showing Codex connected to the PostgreSQL connection.
The showcase endpoint showing Codex connected to the PostgreSQL connection.

The AI app sends a tool name and arguments, such as a connection name and SQL. GateRook checks the endpoint's tool mode and applicable policy, supplies the database credential inside the connector, executes the permitted operation, and records the outcome in Activity.

In Tools & policies, confirm that the three read tools use Read only and sql_execute uses Approval. Keep Bypass unselected for this walkthrough. The endpoint can also display gateway tools in Off mode; those are separate from the four PostgreSQL tools.

The PostgreSQL tools with three Read only modes and sql_execute in Approval mode.
The PostgreSQL tools with three Read only modes and sql_execute in Approval mode.

If an already running AI session still has the old tool list, refresh its MCP tools or reconnect the client before asking it to use the new connection. No database password needs to be copied into the chat.

9. Discover the table and run read queries

Ask your connected AI app:

Use the showcase endpoint and the postgres-demo connection. List the tables in gaterook_demo, describe public.orders, and show the orders sorted by id. Then summarize the order count and total by status.

The schema tools return one table, public.orders, with four columns and an id primary key. A read call uses arguments such as:

Tool arguments
{
  "connection": "postgres-demo",
  "database": "gaterook_demo",
  "sql": "SELECT id, customer_name, status, total FROM public.orders ORDER BY id",
  "limit": 10
}

Before the update, the result is:

idcustomer_namestatustotal
1001Avery Stonepending129.90
1002Morgan Reedpaid89.00
1003Riley Chenpending249.00
1004Jordan Leeshipped49.50

sql_query runs a validated read in a read-only PostgreSQL transaction and rolls that transaction back when finished. Row, response-size, and timeout limits still apply. In the tested configuration, the tool advertises a maximum of 1,000 rows and a five-second timeout; these calls request only ten rows.

Open Activity, filter by the connection or endpoint, and select the corresponding sql_query row. Its details show the client, endpoint, SQL arguments, and decision.

An allowed sql_query event showing Codex, showcase, and the exact SELECT arguments.
An allowed sql_query event showing Codex, showcase, and the exact SELECT arguments.

The policy decision says Allowed: this read ran immediately. The result section shows its execution summary, size, hash, masking count, and timing.

The SELECT result summary with four orders and the read-only policy decision.
The SELECT result summary with four orders and the read-only policy decision.

The second query groups the same data:

SQL query
SELECT status, COUNT(*) AS order_count, SUM(total) AS total_amount
FROM public.orders
GROUP BY status
ORDER BY status;
statusorder_counttotal_amount
paid189.00
pending2378.90
shipped149.50

10. Review and approve one change

Ask the AI app to mark only order 1001 as shipped, provided it is still pending. It should use sql_execute with this exact statement:

SQL query
UPDATE public.orders
SET status = 'shipped'
WHERE id = 1001 AND status = 'pending';

The WHERE clause narrows the target to one known order and checks its starting state. GateRook pauses the operation and returns an approval handle. At this point, the change has not executed.

The chat's approval card shows Waiting for approval and links to GateRook. The following two screenshots show the client-side card before and after the person's decision in the application.

The GateRook approval card in Codex while the UPDATE is waiting and has not executed.
The GateRook approval card in Codex while the UPDATE is waiting and has not executed.

In GateRook's Approvals screen, review:

  • The connection postgres-demo, the DEV marker, and endpoint showcase.
  • The exact SQL, especially its table, SET value, and WHERE clause.
  • The rule dev.sql.write-approval, which requires a person to approve the change.
  • The impact preview: the target public.orders, an estimate of 1 row from EXPLAIN, a transaction that rolls back on error, and a five-second statement timeout.

The row estimate is a planning estimate; the execution result tells you how many rows were actually changed. Add a comment if useful, then select Approve and run. To refuse the request, select Deny. The request also expires if nobody decides before its timer runs out; the example has a five-minute deadline.

The approval applies to this exact action. The AI should poll its existing approval handle for the outcome, rather than submit the update again. Approval happens in GateRook; opening the chat card alone does not approve it.

After approval, the card changes to Completed. The actual result was a committed transaction with 1 row updated.

The same GateRook approval card after the approved operation completed.
The same GateRook approval card after the approved operation completed.

11. Verify the database change

Ask the AI app to read order 1001 again using sql_query:

SQL query
SELECT id, customer_name, status, total
FROM public.orders
WHERE id = 1001;

The result is now:

idcustomer_namestatustotal
1001Avery Stoneshipped129.90

This verifies the saved database state independently of the approval card. The follow-up read is also recorded in Activity.

The follow-up SELECT in Activity showing order 1001 with status shipped.
The follow-up SELECT in Activity showing order 1001 with status shipped.

12. Follow the full audit trail in Activity

Open Activity → Agent calls. Enter this filter and press Enter:

Activity filter
endpoint:showcase connection:postgres-demo

Select the time range that covers your test. In this walkthrough, the filtered list contains six calls: schema discovery, table description, the initial SELECT, the grouped SELECT, the approved UPDATE, and the verification SELECT. Read calls show Allowed; the update shows Approved. Each row identifies the tool, connection, client, endpoint, and execution duration.

Activity filtered to showcase and postgres-demo, showing five allowed reads and one approved update.
Activity filtered to showcase and postgres-demo, showing five allowed reads and one approved update.

Open the sql_execute event to inspect its exact arguments and the policy that required approval.

The approved sql_execute event with its connection, client, endpoint, and SQL arguments.
The approved sql_execute event with its connection, client, endpoint, and SQL arguments.

Scroll to Approval and Result. The event connects the whole sequence: requested by Codex, desktop notification, approved by the person, and executed with one affected row. It also shows an approved-action hash and confirms that the executed action matches the approved action byte for byte.

The approval timeline, matching approved and executed action, and one-row UPDATE result.
The approval timeline, matching approved and executed action, and one-row UPDATE result.

Use this detail view to answer practical questions: Which AI app requested the change? Which endpoint and connection did it use? Why did it need approval? When was it approved? How many rows changed? How long did execution take?

Arguments and Policy decision explain the request and its authorization. Approval records the person's decision. Result and Timing show the outcome and duration. Result detail varies by tool: the read events here show a summary, size, and hash, while the approved write also exposes its structured execution result. Do not treat the audit log as a full database-result archive.

Masking follows the configured policies. These fictional records have no masked fields. Unrelated connection details have been excluded from the screenshots, and the unrelated endpoint name visible during selection has been redacted.

Keep or stop the demo

The tutorial leaves postgres-demo attached to showcase, with reads enabled and writes still requiring approval. The Docker container remains running so you can continue exploring.

To pause access without deleting the configuration, turn the connection's On switch off. That affects this connection across endpoints. Turning an endpoint off instead pauses access through that endpoint. Activity remains available for inspecting previous calls.

To stop the tutorial database while retaining its data:

Shell commands
docker stop gaterook-postgres-showcase

To resume it later:

Shell commands
docker start gaterook-postgres-showcase

Once it is healthy again, use Test connection in GateRook to check connectivity. A stopped container will make the connection unavailable until it is restarted.

Useful access. Explicit control.

What you can do with PostgreSQL and AI

Trace relationships in a database

Use schema discovery and table descriptions to inspect primary keys, foreign keys and indexes. The agent can explain a relationship using the actual schema instead of guessing table names from your prompt.

Investigate query performance

Ask for EXPLAIN of a specific SELECT and compare it with the available indexes. Start with a bounded query and a statement timeout; database work still consumes resources even when it only reads.

Separate environments

Keep a stage connection and a production read connection on separate endpoints or with distinct modes. The visible environment and per-connection permissions make the intended target clear in each call.

Connection settings

Configure PostgreSQL in GateRook

These are example values for the connection form. Enter credentials into GateRook’s secret fields, not into an AI prompt. Requirements and alternatives are noted per field.

PostgreSQL connection configuration
SettingExampleHow to use it
Connector typePostgreSQLChoose the built-in connector in Connections.
Name / environmentpostgres-demo / DEV DevelopmentUse the tutorial connection name in tool calls and Activity filters. Mutations still require approval.
Host / port127.0.0.1 / 15432The tutorial container publishes PostgreSQL only on the loopback interface of the computer running GateRook.
Database / discovery databasegaterook_demoSet the discovery database in Advanced, load the list, and select only gaterook_demo.
User / passworddemo_agent / local-demo-onlyUse Encrypted here. This public, disposable password is only for the local fixture; the role has SELECT and UPDATE on public.orders.
SSL modeOff (disable)Only for this loopback-only container without TLS. For a remote database, use verify-full and provide its CA certificate when needed.
Schema allowlist / default schemapublicAdd public as an allowlist chip and use it as the default schema.
EndpointshowcaseSelect only showcase. Use Read only for the three read tools and Approval for sql_execute; leave Bypass unselected.

Know what you expose

PostgreSQL tools and access boundaries

The connector defines available operations. GateRook’s MCP Firewall enforces endpoint modes and connection policies before an AI client can use them.

Available tools and access behavior
ToolPurposeAccess behavior
sql_list_schemasDiscover the schemas, databases and tables visible to the connection user.Read only
sql_describe_tableInspect columns, types, indexes and foreign keys before writing a query.Read only
sql_queryRun a read query or EXPLAIN in a read-only transaction, with endpoint limits.Read only
sql_executePropose INSERT, UPDATE or DELETE. You review and approve the exact SQL before execution.Approval

Before you enable access

  • sql_query runs reads in a read-only transaction. sql_execute is a separate tool and requires approval for changes; a read-only database login still cannot write after approval.
  • The endpoint caps rows and execution time. Do not treat a truncated result as the full dataset.
  • Unknown user-defined functions are not automatically trusted as reads: they require approval, and are refused on prod unless allowed by policy.
  • A query result can contain application data. Choose tables, columns and access scope deliberately before exposing them to an AI app.

GateRook stores local connection secrets encrypted and resolves them for connectors. Allowed tool results are returned to your AI client and may be processed by its provider. Scope the data you expose as well as the actions you allow.

Practical answers

PostgreSQL connection questions

Use Test connection to isolate service access problems. Use Playground and Activity to inspect endpoint permissions and tool calls.

Is GateRook a PostgreSQL MCP server or an AI client?

GateRook connects to PostgreSQL and exposes selected database tools through an MCP endpoint. Your AI app is the MCP client. It receives the endpoint configuration, while the database password stays with the GateRook connection.

Can the AI change database records?

In this walkthrough, sql_execute uses Approval mode. The policy must permit the statement, the database role must have permission, and you must approve the exact action. Keep Bypass unselected to preserve this review step.

How do I restrict access to a PostgreSQL schema?

Set the connection Schema allowlist, keep the database role privileges narrow, and apply the environment policy. The default schema is public unless changed in Advanced settings.

Do I need to expose the database to the public internet?

No. The local GateRook core connects from your computer, so an existing VPN and private network route can be used. The database must be reachable by that computer.

Keep exploring

MySQL

Control MySQL access through GateRook’s MCP Firewall. Configure a scoped login, run read queries, approve an UPDATE and inspect each call in Activity.

MongoDB

Control MongoDB access through GateRook’s MCP Firewall. Follow the Docker tutorial to scope reads, approve updates and inspect the Activity audit trail.

Redis

Protect Redis access with scoped, read-only MCP tools. Follow the GateRook Docker tutorial to approve a value read and inspect its Activity record.

Browse all integration guides

Your MCP Firewall. Your access rules.

Control AI access to PostgreSQL.

Start with read-only access. Approve changes. Inspect the audit trail.

Read the getting started guide

Get GateRook

Download GateRook 0.9.2 for your Mac, or get the Windows app from Microsoft Store.

macOS

Version 0.9.2 for Apple Silicon (arm64). This download does not support Intel Macs.

Open the DMG and drag GateRook to Applications.

Windows

Available for free from Microsoft Store. Install GateRook and receive updates through the Store.

macOS release notes and checksums (opens in a new tab)