Missing or incomplete audit trails let attackers erase their footprints and make post‑mortems impossible.
Today many teams rely on MCP gateways to route traffic from AI assistants or custom runtimes into PostgreSQL. The gateway abstracts the database endpoint, allowing developers to invoke queries without embedding credentials in code. In practice, the connection is often opened with a long‑lived service account and left running for weeks. Engineers share the same endpoint, and the gateway does not emit a unified log of who ran which statement. When a rogue query modifies or deletes rows, the only evidence may be a fleeting console output that disappears after the session ends. The result is a blind spot: you know something happened, but you cannot prove who, when, or what data was touched.
This situation satisfies a basic prerequisite – the request reaches PostgreSQL through an MCP gateway – but it leaves the critical control plane untouched. The gateway still forwards the raw SQL payload directly to the database engine. No inline masking runs, no just‑in‑time approval step intercepts risky statements, and no session recording persists after the connection closes. In other words, the request bypasses any enforcement layer that could generate a reliable audit trail.
Why the audit trail matters for Postgres
Regulators, auditors, and security teams require a reliable audit trail that records who accessed what data and when. An audit trail must capture the identity of the caller, the exact statement executed, and the response returned. For PostgreSQL, this means logging SELECT, UPDATE, DELETE, and DDL operations with enough context to reconstruct the impact. Without a trustworthy audit trail, you cannot demonstrate compliance, investigate incidents, or enforce least‑privilege policies. The gap becomes especially dangerous when AI‑driven agents generate queries on‑the‑fly, because the originating code may not retain any human‑readable history.
Placing the enforcement layer in the data path
To close the gap, the enforcement point must sit between the identity source and the PostgreSQL endpoint. This is the only place you can observe every packet, apply policy, and record the interaction before the database processes the request. hoop.dev fulfills that role. It acts as a Layer 7 gateway that proxies the connection, inspects each SQL command, and writes a complete audit entry for every session. Because the gateway owns the credential used to talk to PostgreSQL, the client never sees the secret, and the database cannot be reached directly without passing through the gateway.
When a user or an AI agent initiates a connection, hoop.dev verifies the OIDC token, extracts group membership, and maps that to a policy that defines what statements are allowed. If a statement matches a risky pattern – for example, a DROP TABLE or a mass UPDATE without a WHERE clause – hoop.dev can block it outright or route it for manual approval. Approved statements continue to the database, while blocked ones generate an alert and are recorded as denied attempts. Every response, including result sets that contain sensitive columns, can be masked in real time, ensuring that downstream logs never expose PII.
Because the gateway records each request and response, you obtain a durable audit trail that includes:
