Give coding agents safe write access to database config

Coding agents now edit the config apps read from their own database: model routing, prompts, feature flags, pricing. Give an agent raw write access and it can change anything with no preview, no record and no undo. Give it read-only access and it cannot do the job.

This page shows a middle path: the agent writes, but through a layer that previews the change, refuses to overwrite edits it has not seen, records every write and can undo any of them.

The problem with raw write access

A database MCP server with write access lets an agent run any update. Three things go wrong with config:

The usual advice is to give agents read-only access. That is safe, and it also means the agent cannot do the job when the job is to change config.

What a safe write path needs

  1. A preview of the exact change before anything is written.
  2. A refusal when the record changed since it was last recorded, instead of a silent overwrite.
  3. A record of every write: who, when, why and what changed.
  4. An undo to any earlier version.
  5. Limits per environment, so production can be stricter than dev.

cfgit is an open-source CLI and MCP server built around those five, for config in MongoDB and Postgres. The rest of this page shows what an agent actually sees, with responses from a real run of cfgit 0.6.5.

Set up cfgit for your agent

Point cfgit at your config collections or tables first (the MongoDB and Postgres guides take about ten minutes). Then add the MCP server. In Claude Code:

claude plugin install cfgit --marketplace AusafMo/cfgit

Any other MCP client can run it with CFG_CONFIG pointing at your .cfg.toml:

CFG_CONFIG=/path/to/.cfg.toml uvx --with='cfgit[mcp,mongo,postgres]' cfgit mcp

It is listed on the official MCP Registry as io.github.AusafMo/cfgit, and Codex, Cursor and Claude Desktop installs are in the setup menu on the cfgit page.

Preview before every write

Every write tool takes dry_run. The agent asks for the change and gets back the field-level delta, with nothing written:

// cfg_set {"record": "pricing_rules:pro_monthly", "assignments": ["price_usd=39"],
//          "message": "pro to 39", "dry_run": true}
{
  "status": "ok",
  "data": {
    "state": "would_commit",
    "changes": [
      { "path": "price_usd", "op": "change", "before": 29, "after": 39 }
    ],
    "validation_problems": [],
    "impact": { "affected_records": [], "code_references": [] }
  },
  "next": {
    "why": "Dry run: this is the field-level delta cfgit would write. Nothing was written.",
    "remedy": "Rerun the same command without --dry-run (dry_run=false) to apply."
  }
}

For riskier records, cfg_impact lists the other records and the lines of code that read the record, with a risk level, before the agent commits.

Refuse to overwrite unseen edits

Here someone changed the team plan from an admin panel after cfgit last recorded it. The agent tries to change the price:

// cfg_set {"record": "pricing_rules:team_annual", "assignments": ["price_usd=300"],
//          "message": "annual to 300"}
{
  "status": "dirty",
  "data": { "state": "changed_outside_cfgit" },
  "next": {
    "why": "The live record differs from what cfgit last recorded: something wrote it outside cfgit.",
    "remedy": "Look at the drift. Keep it with adopt, or throw it away with restore --discard-drift (the discarded doc stays in history). Then retry.",
    "actions": [
      { "tool": "cfg_diff", "args": { "record": "pricing_rules:team_annual", "a": "=HEAD", "b": "=live" } },
      { "tool": "cfg_adopt", "args": { "record": "pricing_rules:team_annual" }, "writes": true },
      { "tool": "cfg_restore", "args": { "record": "pricing_rules:team_annual", "discard_drift": true }, "writes": true }
    ]
  }
}

Nothing was written. The response tells the agent what happened and which tools come next, and marks the ones that write, so a well-behaved agent can show the diff and ask you before adopting or discarding. More on this in detecting config drift.

A record of every write

Each write is a new version with the author, the message, the time and the field-level change. cfg log (or cfg_log) shows it:

$ cfg log pricing_rules:pro_monthly
pricing_rules:pro_monthly @2 fad3769197b3
  change price_usd
    before: 29
    after:  35
  change trial_days
    before: 14
    after:  7
...

As JSON, each entry also carries the author and how that identity was established:

{
  "seq": 2,
  "op": "commit",
  "author": "dev@example.com",
  "message": "raise pro to 35, shorter trial",
  "meta": {
    "identity": { "author": "dev@example.com", "mode": "open", "source": "self_asserted" }
  }
}

Undo in one step

Any version can be put back. The restore is itself a new version, so the history keeps everything:

$ cfg restore pricing_rules:pro_monthly @1 -m "back to 29 while we test"
pricing_rules:pro_monthly: restored @3  622738e77f26

Limits per environment

Each environment in .cfg.toml can be stricter than the last. Some options:

[env.prod.identity]
mode = "authenticated"
sources = ["token"]
token_env = "CFGIT_IDENTITY_TOKEN"

[env.prod.permissions]
mode = "restricted"
admins = ["owner@example.com"]
writers = ["*@example.com"]

The details are in the cfgit guide.

What it does not do

Questions

Is read-only database access enough for coding agents?

It is the safest default for exploring data, but then the agent cannot do the work when the task is to change config. A guarded write path lets it make the change while keeping a preview, a record and an undo.

What stops an agent from overwriting an edit someone made by hand?

cfgit compares the live record with the last recorded version before every write. If they differ, the write is refused and the agent is told how to look at the change and who should decide.

Can I see what the agent changed?

Yes. Every write is a version with the author, the message and the field-level change. cfg log shows it, and cfg restore puts any earlier version back.

Can I keep agents away from production?

Yes. Give the agent a dev environment only and move changes with cfg promote, require a verified identity in production, restrict who can write per environment, or have agents commit to a draft branch that a person merges.

Does the agent still need direct database credentials?

It should not have them. Give it the cfgit MCP server instead of a raw MongoDB or Postgres MCP server, otherwise it can write around the checks.