Lock rows for AI agents.
lokra.dev · Docs · Lokra Cloud
Lokra is an MCP server that sits between your AI agents and Postgres. You write one
policies.yaml, and Lokra turns it into a Postgres role per agent, with grants, row-level
security and masking. Postgres itself decides what each agent can read. Writes are dry-run
and wait for a person, and every request goes into a signed, hash-chained log.
It works with Claude Code, Claude Desktop, Cursor, VS Code, Windsurf and any other MCP client.
Try it
brew install lokrahq/tap/lokra # or: pipx install lokra
lokra demo
The demo starts a throwaway Postgres in Docker, points two agents at it and cleans up when
it's done. No Docker? lokra demo --dsn "postgresql://..." runs in its own schema on any
Postgres where you can create roles.
Use it on your database
lokra init "postgresql://user:pass@host:5432/app" # read-only, writes policies.yaml
lokra check --dsn "postgresql://user:pass@host:5432/app" # typos, unmasked PII columns
lokra provision --admin-dsn "postgresql://admin:pass@host:5432/app" # roles, grants, row-level security
lokra connect # adds the agent to Claude Code
init only reads. It marks columns that look like emails, phone numbers or ID numbers so
you can mask them. provision needs a role that can create roles, not a superuser, so the
RDS master user and Supabase's postgres user both work. For other clients, use
lokra connect --client cursor (or claude-desktop, vscode, windsurf).
A policy looks like this:
database: {host: db.internal, port: 5432, dbname: app}
agents:
support-bot:
rows: {column: account_id, values: [42]} # only account 42's rows, enforced by Postgres
read:
customers: [id, name, email]
orders: "*"
ops-bot:
read: {orders: "*"}
write: {orders: [update]}
approval: {auto_max_rows: 1} # one-row updates run, bigger ones wait for you
rate_limit: 60 # requests a minute
masking:
columns: {email: redact, phone: last3}
Put lokra check --strict in CI and the build fails when someone adds a column that nothing masks.
What you get
- Each agent logs in as its own Postgres role and sees only the tables and columns in its policy. It gets a short-lived signed token, never a password.
- Rows can be locked to fixed values, or per request: one support agent serves every customer and only sees the signed-in customer's rows, taken from your app's token or your login provider's. See one agent for every customer.
- Emails, phone numbers, cards, IBANs, SSNs and Australian Medicare and IHI numbers are masked
in columns, free text and JSON. A masked column can't be pulled out through a function, an
alias or
row_to_json. - Every INSERT, UPDATE and DELETE is dry-run and shown with the rows it would change, before
and after. Approve it in the terminal, the local dashboard, Slack or Lokra Cloud. Small writes
can run on their own, deletes can need two people, and
lokra undoputs the rows back for 7 days. An agent that has moved on can have Lokra run its write the moment it's approved. lokra pause support-botrefuses the agent's requests, blocks its database login and ends its sessions.lokra revoke-tokenkills one leaked token.lokra exposurelists whose data an agent read or changed,lokra reportflags probing and runaway loops, andlokra evidencewrites an audit pack mapped to ISO 27001 and the Essential Eight.
Why Postgres enforces it
Several "read-only" database MCP servers were bypassed in 2025 and 2026 because they decided what was safe by parsing SQL. Lokra checks SQL too, but that isn't the boundary. The limits live in Postgres, so a query that gets past the check still meets them:
| Layer | Stops | Enforced by |
|---|---|---|
| Signed short-lived token | Unknown, forged or expired agents | Lokra (HMAC) |
| SQL check | Writes in the read tool, stacked statements, DDL, SET ROLE |
Lokra (sqlglot), fails closed |
| Per-agent login role | Tables and columns outside the policy | Postgres grants |
| Row lock | Rows outside the agent's scope, for reads and writes | Postgres row-level security |
| Read-only transaction | Writes hidden in CTEs or functions | Postgres |
| Prepared statements only | COMMIT; DROP ... style stacking |
Postgres protocol |
| Statement timeout | Runaway queries | Postgres role setting |
| Masking | Identifiers in results, and masked columns leaving under another name | Lokra |
| Ledger | Silent edits or deletions of history | SHA-256 chain and HMAC |
The tests in tests/test_integration.py turn the SQL check off and run the attacks anyway, to
show the database still blocks them. More in the security model.
Running it for real
- Agents on other machines connect over HTTP:
lokra serve --httpbehind TLS, with a token per agent fromlokra mint-token. See production. - Every release is also an image for amd64 and arm64:
docker run -p 8787:8787 --user "$(id -u):$(id -g)" -v "$PWD:/work" ghcr.io/lokrahq/lokra:0.8 lokra slackposts each pending write to a channel with Approve and Deny buttons. It connects out over Socket Mode, so Lokra needs no public URL. See Slack.- Lokra Cloud is one inbox for all your gates, with phone approvals and
team roles.
LOKRA_CLOUD_TOKEN=lkg_... lokra cloudsends it masked SQL, counts and the ledger, never query results. It's free to start.
Docs
Quick start · Policies · Row locks · Approvals · Masking · Policy reference · Troubleshooting
Contributing
Issues and pull requests are welcome. See CONTRIBUTING.md to set up the lab database and run the tests. Report security issues privately, as described in SECURITY.md.
License
Apache-2.0. See LICENSE.
Metadata
Release files for lokra 0.8.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lokra-0.8.6.tar.gz | 162.5 kB | With provenance | Details for lokra-0.8.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lokra-0.8.6-py3-none-any.whl | Python 3 | none | any | Details for lokra-0.8.6-py3-none-any.whl |
Total release size: 298.0 kB
Release files / lokra-0.8.6.tar.gz
| Download URL | lokra-0.8.6.tar.gz |
|---|---|
| Size | 162.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1e672554082abb85a938809a5430a8a87035e92fa77110b9dae190b51d2775d
|
|
BLAKE2b-256 checksum How to use checksums |
3e95a767103ad14d9fd34129a8bba1d22adc5e2af22a03290b524408984598eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / lokra-0.8.6-py3-none-any.whl
| Download URL | lokra-0.8.6-py3-none-any.whl |
|---|---|
| Size | 135.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
acab0ae11df613abe0771bc5612d476f56c1a0905ea1b93fdeb025fdbee3a368
|
|
BLAKE2b-256 checksum How to use checksums |
202961454aacbdec33f51ac99020a0639820e3f2bb05bcc475d7c01842ac3a92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logSecurity for lokra 0.8.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for lokra-0.8.6.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.