Lokra
Postgres gate for AI agents with row locks, masking and approved writes
Lokra is an open-source MCP server for databases. It runs locally on your machine and is started by your AI client.
- Pricing
- Open source
- Platforms
- CLI, API, Self-hosted
- Runs
- Locally
- What it can do
- Can change data (3 tools)
- Access
- Needs a secret key or token
- Version
- 0.8.6
Similar MCP servers
Install
You install MCP servers on a computer. Send yourself the link.
Add with the CLI
Run in a terminal
claude mcp add lokra --env LOKRA_CONFIG='<LOKRA_CONFIG>' --env LOKRA_TOKEN='<LOKRA_TOKEN>' -- uvx lokraAdd --scope user to use it in every project, or --scope project to share it in .mcp.json.
Or share it with your project
Add to .mcp.json
{
"mcpServers": {
"lokra": {
"command": "uvx",
"args": [
"lokra"
],
"env": {
"LOKRA_CONFIG": "<LOKRA_CONFIG>",
"LOKRA_TOKEN": "<LOKRA_TOKEN>"
}
}
}
}Add to claude_desktop_config.json
{
"mcpServers": {
"lokra": {
"command": "uvx",
"args": [
"lokra"
],
"env": {
"LOKRA_CONFIG": "<LOKRA_CONFIG>",
"LOKRA_TOKEN": "<LOKRA_TOKEN>"
}
}
}
}Settings → Developer → Edit Config, then quit and reopen Claude Desktop.
Add to ~/.cursor/mcp.json
{
"mcpServers": {
"lokra": {
"command": "uvx",
"args": [
"lokra"
],
"env": {
"LOKRA_CONFIG": "<LOKRA_CONFIG>",
"LOKRA_TOKEN": "<LOKRA_TOKEN>"
}
}
}
}Use .cursor/mcp.json in a project to share it with the project.
Add to ~/.copilot/mcp-config.json
{
"mcpServers": {
"lokra": {
"type": "stdio",
"command": "uvx",
"args": [
"lokra"
],
"env": {
"LOKRA_CONFIG": "<LOKRA_CONFIG>",
"LOKRA_TOKEN": "<LOKRA_TOKEN>"
}
}
}
}Or put the same entry in .mcp.json at your workspace root to share it.
Add with the CLI
Run in a terminal
codex mcp add lokra --env LOKRA_CONFIG='<LOKRA_CONFIG>' --env LOKRA_TOKEN='<LOKRA_TOKEN>' -- uvx lokraOr add to config.toml
Add to ~/.codex/config.toml
[mcp_servers.lokra]
command = "uvx"
args = ["lokra"]
env = { LOKRA_CONFIG = "<LOKRA_CONFIG>", LOKRA_TOKEN = "<LOKRA_TOKEN>" }Add to your client's MCP settings (most use this shape)
{
"mcpServers": {
"lokra": {
"command": "uvx",
"args": [
"lokra"
],
"env": {
"LOKRA_CONFIG": "<LOKRA_CONFIG>",
"LOKRA_TOKEN": "<LOKRA_TOKEN>"
}
}
}
}Gemini CLI and Antigravity
Gemini CLI
Add to ~/.gemini/settings.json
{ "mcpServers": { "lokra": { "command": "uvx", "args": [ "lokra" ], "env": { "LOKRA_CONFIG": "<LOKRA_CONFIG>", "LOKRA_TOKEN": "<LOKRA_TOKEN>" } } } }Or run: gemini mcp add -s user -e LOKRA_CONFIG='<LOKRA_CONFIG>' -e LOKRA_TOKEN='<LOKRA_TOKEN>' lokra uvx -- lokra
Antigravity
Add to ~/.gemini/config/mcp_config.json
{ "mcpServers": { "lokra": { "command": "uvx", "args": [ "lokra" ], "env": { "LOKRA_CONFIG": "<LOKRA_CONFIG>", "LOKRA_TOKEN": "<LOKRA_TOKEN>" } } } }Use .agents/mcp_config.json to add it to one workspace only.
Devin Desktop (formerly Windsurf)
Add to ~/.config/devin/mcp_config.json
{ "mcpServers": { "lokra": { "command": "uvx", "args": [ "lokra" ], "env": { "LOKRA_CONFIG": "<LOKRA_CONFIG>", "LOKRA_TOKEN": "<LOKRA_TOKEN>" } } } }On Windows the file is %APPDATA%\devin\mcp_config.json. Use .devin/mcp_config.json to share it with a project.
Cline
Add to cline_mcp_settings.json
{ "mcpServers": { "lokra": { "command": "uvx", "args": [ "lokra" ], "env": { "LOKRA_CONFIG": "<LOKRA_CONFIG>", "LOKRA_TOKEN": "<LOKRA_TOKEN>" } } } }Open it from the MCP Servers icon → Configure → Configure MCP Servers.
Zed
Add to Zed settings.json
{ "context_servers": { "lokra": { "command": "uvx", "args": [ "lokra" ], "env": { "LOKRA_CONFIG": "<LOKRA_CONFIG>", "LOKRA_TOKEN": "<LOKRA_TOKEN>" } } } }Open it with zed: open settings file. Merge context_servers into the settings you already have.
JetBrains AI Assistant and Junie
AI Assistant
Add to Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add
{ "mcpServers": { "lokra": { "command": "uvx", "args": [ "lokra" ], "env": { "LOKRA_CONFIG": "<LOKRA_CONFIG>", "LOKRA_TOKEN": "<LOKRA_TOKEN>" } } } }The AI Assistant docs only show command and args. If the env block is ignored, use Junie for this server.
Junie
Add to ~/.junie/mcp/mcp.json
{ "mcpServers": { "lokra": { "command": "uvx", "args": [ "lokra" ], "env": { "LOKRA_CONFIG": "<LOKRA_CONFIG>", "LOKRA_TOKEN": "<LOKRA_TOKEN>" } } } }Use .junie/mcp/mcp.json to share it with a project.
Kiro
Add to ~/.kiro/settings/mcp.json
{ "mcpServers": { "lokra": { "command": "uvx", "args": [ "lokra" ], "env": { "LOKRA_CONFIG": "<LOKRA_CONFIG>", "LOKRA_TOKEN": "<LOKRA_TOKEN>" } } } }Use .kiro/settings/mcp.json to add it to one workspace only.
Using several servers? Build one config file with the MCP config generator.
Configuration
LOKRA_CONFIGPath to the policies.yaml that defines this agent's accessRequiredLOKRA_TOKENThe agent's token, from lokra mint-token <agent>Required
About Lokra
Lokra runs between an agent and a Postgres database and decides what that agent can read and change. Each agent logs in with its own database role, limited to the tables, columns and rows its policy allows, so the database itself enforces the scope instead of an application-level check.
Requests pass through several layers in order: a signed short-lived token, a SQL check that refuses DDL and stacked statements, the agent's own role, a read-only transaction, masking of identifiers such as emails, phone numbers and payment cards, and a hash-chained audit ledger. Writes are dry-run first, show how many rows they would change, and wait for a person to approve them, unless an approval rule lets a small write through.
The gate is an MCP server that runs next to your database, under an Apache-2.0 licence. It suits teams that want agents to query production data without handing them the application's database password.
Tools this server provides (6)
Taken from the project documentation; the running server may differ.
From the tool list in its README, going by the names, 3 of 6 tools change data; 1 name doesn't say.
From the server's own tool labels and tool names; not verified by us.
- whoami
- Shows the calling agent's identity.
- list_tablesName suggests: reads
- Lists tables the agent can access.
- queryName suggests: reads
- Runs a read-only SELECT with masking applied.
- propose_writeName suggests: changes
- Submits a write for dry run and approval.
- write_statusName suggests: changes
- Checks the status of a proposed write.
- execute_writeName suggests: changes
- Runs an approved write.
What it does
- Per-agent database roles
- Each agent gets its own Postgres role with grants only on the tables and columns in its policy.
- Row-level locks
- Row-level security policies restrict an agent to rows whose column matches listed values.
- Masking of sensitive values
- Emails, phone numbers, cards, IBANs and several national identifiers are masked in results, including inside free text and JSON.
- Approved writes
- INSERT, UPDATE and DELETE are dry-run and held for a person to approve, with optional rules for small or two-person approvals.
- Signed audit ledger
- Every request and write decision is appended to a hash-chained, signed log with a report command for activity and risk summaries.
- Pause and revoke controls
- Agents can be paused or have individual tokens revoked, which also blocks their database login when an admin connection is set.
Good for
- Letting a support bot read customer records without seeing card or contact details
- Having an operations agent propose database updates that a staff member approves first
- Connecting Claude Code or Cursor to a Supabase or RDS database with a restricted role
- Producing an audit trail of agent database access for a security review
Pricing
Open source, from $49 a month
Open source gate, free; Lokra Cloud free plan, then $49/mo for the team
Prices change. Check lokra.dev before you buy.
Lokra FAQ
Is Lokra free?
The gate is open source under Apache-2.0 and free with no limits. Lokra Cloud has a free plan and a flat $49 a month for the whole team.
Does the agent ever see my database password?
No. Agents receive a short-lived signed token and log in as their own limited Postgres role.
Which databases are supported?
Lokra is tested on Postgres 16 and works with hosted Postgres such as Supabase and Amazon RDS.
How are writes handled?
Writes are dry-run to count affected rows and held until approved by a person, through the terminal, dashboard or Slack. A write that would change more rows than approved is rolled back.
How do I add Lokra to Claude Code?
Run this command in your terminal: claude mcp add lokra --env LOKRA_CONFIG='<LOKRA_CONFIG>' --env LOKRA_TOKEN='<LOKRA_TOKEN>' -- uvx lokra
What are the best alternatives to Lokra?
The closest alternatives to Lokra are Lomberk, Pgmoat, pgleash, Orion Gate and pgbrake.
Where this comes from
- Description: written from the project's README, the project's website and its MCP Registry entry.
- Install steps: from the official MCP Registry entry.