Derbent

io.github.tunahanaliozturkv1.0.0更新于 Oct 2, 2026

Gate for coding agents' MCP and built-in tool calls: rules, approvals and hash-chained receipts

概览

AI 生成的概览

Derbent 是一个本地网关,对编码代理的每次工具调用(MCP 或内置工具)进行规则判定、审批和记录。

功能
Derbent 位于编码代理与其工具之间,用一套规则按代理、工具和参数对每次调用做出允许、拒绝或询问的判定。它把每次调用记录为哈希链式收据,可用 derbent verify 检查是否被编辑、移动或删除,并在终端界面中等待你批准规则要求询问的调用。它还提供按仓库共享的笔记与代理间任务交接、针对下游工具定义变化的固定(pins),以及阻止代理陷入循环的预算。
适用场景
如果你使用 Claude Code、Codex、GitHub Copilot CLI 或 Antigravity CLI 等编码代理,并希望用统一策略和审计记录覆盖它们的 MCP 与内置工具调用,就值得添加。适合希望 git push、rm -rf 等风险命令先等待你批准,或需要防篡改的代理操作记录的场合。
运行要求
需要 Windows、macOS 或 Linux 的本地二进制文件,可从发行版、Homebrew、Scoop 安装,或用 Go 1.27 及以上自行构建。无需守护进程、网络监听、账户或 API 密钥;SQLite 文件是唯一的共享状态。安装时运行 derbent init 为各 CLI 添加 MCP 条目和工具调用前钩子,规则存放在用户配置目录的 config.toml 中。
安装前请注意
它不是沙箱:已经能以你的身份运行 shell 命令的代理可以绕过它,也能自己运行 derbent approve。审批依赖你盯着;无人值守时,ask 会在默认 50 秒超时后被拒绝。收据会遮蔽机密但仍保留参数,能写入数据库的人可以重写或删除整条链,因此请把打印的链头哈希另存他处。参数通配符匹配的是字符串而非语义,针对命令前缀的 allow 规则会放行任意选项。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Derbent,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

[Derbent]

Derbent

One guarded pass for all your coding agents.

Every tool call that reaches Derbent, MCP or a CLI's built-in tools, is decided by one policy and written to a tamper-evident log, and the calls you care about wait for you.

[A terminal session: derbent explain shows that git push origin main matches an ask rule; Claude Code hook calls fed to derbent gate let go test run and deny rm -rf by a rule; derbent receipts lists both calls and derbent verify finds the chain intact; after one receipt is edited with sqlite3, derbent verify names receipt 2 as where the chain breaks]

Derbent guards against mistakes and prompt injection, and keeps an audit trail. It is not a sandbox: an agent that can already run shell commands as you can get around it (see Limits).

In Turkish history, a derbent was a guarded post on a mountain pass: its keepers decided who went through and kept a record of everyone who did. Derbent does the same for your coding agents' tool calls.

Claude Code, Codex, GitHub Copilot CLI and Antigravity CLI connect to Derbent as one MCP server, and your other MCP servers sit behind it. Each CLI's pre-tool hook sends its built-in tools, such as the shell and file edits, through the same gate. Every call is decided by your rules and written down.

Support for Codex and Antigravity CLI is experimental (configured from their docs, not yet checked in a real session).

[Four coding agent CLIs send MCP calls to derbent mcp and built-in tool calls to the derbent gate hook; both write a receipt to derbent.db, which the derbent terminal UI reads to show and approve calls, allowed MCP calls go on to your MCP servers, and a built-in call that is not denied runs in the CLI, which still applies its own permission check to a rule allow]

It is one binary for Windows, macOS and Linux. There is no daemon and no network listener: a SQLite file is the only shared state (ADR 0001).

What you get

  • Rules that allow, deny or ask, by agent, tool and argument. The first match wins. The same rules apply to MCP tools and to built-in tools such as the shell, in all four CLIs, and a repository can add project rules that only make them stricter.
  • Approvals. A call your rules ask about waits until you press a in the terminal UI, or is denied after 50 seconds by default.
  • Receipts. Every call gets a hash-chained receipt, and derbent verify names the first receipt where the chain breaks after one was edited, moved, inserted or removed. Keep the head hash it prints to catch the newest ones being deleted too.

Also:

  • Shared memory and handoffs. Agents keep notes per repository and can leave tasks for each other.
  • Pins hold back a downstream server's tool when its definition changes.
  • Budgets stop an agent stuck in a loop.

Install

Download the binary for your system and SHA256SUMS from the latest release, check the hash, and put it on your PATH as derbent (derbent.exe on Windows):

bash
# Linux on amd64; the other files differ only in the end of the namecurl -LO https://github.com/tunahanaliozturk/derbent/releases/download/v1.0.0/derbent-v1.0.0-linux-amd64curl -LO https://github.com/tunahanaliozturk/derbent/releases/download/v1.0.0/SHA256SUMSsha256sum --ignore-missing -c SHA256SUMSinstall -m 755 derbent-v1.0.0-linux-amd64 ~/.local/bin/derbent

Or build it with Go 1.27 or later:

bash
go install github.com/tunahanaliozturk/derbent/cmd/derbent@latest

Homebrew (brew install tunahanaliozturk/tap/derbent) and Scoop install it too; see Install and set up.

Every release can be rebuilt byte for byte from its tag. Install and set up has the other systems, how to check a release, and each CLI's entries by hand.

Quick start

bash
derbent init --preset balanced   # add Derbent to each CLI it finds, and write a first configderbent doctor                   # check what init wrotederbent                          # open the terminal UI in a terminal of its own

derbent init shows every change and asks once before it makes any. It copies each file it changes first and never replaces an entry you already have. With --dry-run it only shows the changes. Two of them, from a real run with the paths shortened:

text
claude: ~/.claude.json  copied first to ~/.claude.json.derbent-backup-20260930T205424Z  runs:    claude mcp add --scope user derbent -- ~/bin/derbent mcp --agent claudederbent: ~/.config/derbent/config.toml  a new file  adds the balanced preset (derbent init --preset balanced --print shows it)

It also adds the derbent gate hook to each CLI's settings; Install and set up shows every entry. Start your agents as usual. Their calls now appear in the UI, and calls the rules ask about wait there for you. Built-in tools says what each CLI's hook covers.

To put your other MCP servers behind the gate, so each agent needs only the one derbent entry, see Downstream servers.

How a call is decided

[A tool call is checked against your rules, where the first match wins, then against the project's rules, which can only make it stricter, then against budgets; the result is allow, ask, which waits for you, or deny, and every call gets one receipt]

Rules live in config.toml in your user config directory (%AppData%\derbent\ on Windows, ~/.config/derbent/ on Linux, ~/Library/Application Support/derbent/ on macOS). A downstream MCP server's tools are named <server>__<tool>, and a CLI's built-in tools native__<tool>:

toml
[[rule]]tool   = "github__issue_read"action = "allow"
[[rule]]tool   = "github__*"          # every other GitHub tool waits for youaction = "ask"
[[rule]]agent  = "claude"tool   = "native__Bash"       # Claude Code's shell, through the hookargs   = { command = "git push*" }action = "ask"
[[rule]]action = "allow"              # the last rule has no condition

To see how a call would be decided before it happens:

bash
derbent explain --agent claude --tool native__Bash --args '{"command":"git push origin main"}'

It prints each rule and why it matches or not, down to the first match, then the project's rules, budgets, pin and grant, and ends with verdict: ask (rule:3) for this call under the rules above. Rules covers globs, the three presets (watch, balanced, strict), project rules, budgets and rule suggestions.

Receipts

[Each receipt stores who called which tool, the decision and a hash of the result, plus the hash of the receipt before it; derbent verify recomputes the chain and names the first broken receipt, and the head hash can be kept elsewhere to check an export]

bash
derbent verify                              # count, head hash, and whether the chain is intactderbent receipts --agent codex --since 1h   # also --tool, --project, --limit, --json

A receipt keeps the arguments after masking secrets, and only the size and hash of what a tool returned (ADR 0004). Someone who can write the database could still rewrite the whole chain or delete the newest receipts, so keep the head hash somewhere else if you want to be able to tell later. Receipts and verify covers exports that can be checked without the database.

Commands

CommandWhat it doesMore
derbentTerminal UI: waiting calls, agents, live receipts, memory, grantsApprovals
derbent init, derbent doctorAdd Derbent to each CLI, then check the setupInstall
derbent mcp --agent <name>The MCP server each CLI startsInstall
derbent gate --agent <name>The pre-tool hook for built-in toolsBuilt-in tools
derbent pending, approve, denyAnswer waiting calls from any shellApprovals
derbent grants, revokeList and take back session grantsApprovals
derbent explainShow how a call would be decidedRules
derbent suggestPrint the rules your answers point toRules
derbent config checkValidate the config and list each server's toolsServers
derbent pinsSee and accept changed downstream toolsServers
derbent receipts, verifyRead, export and verify receiptsReceipts
derbent handoffsList the tasks agents left for each otherMemory and handoffs
derbent versionPrint the release

Overhead

Measured on GitHub's hosted runners on 2026-10-01 (Linux on an Intel Xeon Platinum 8370C, Windows on an AMD EPYC 9V74, 4 vCPUs each), median of ten runs at p50, from docs/benchmark-results:

LinuxWindows
MCP tool call, direct to the server256.5 µs293.0 µs
MCP tool call, through the gate756.0 µs909.0 µs
Starting the binary and exiting4.292 ms40.40 ms
Hook call, derbent gate, allowed6.421 ms64.51 ms

The gate adds 499.5 µs to an MCP call on Linux and 616.0 µs on Windows, for the extra stdio hop, the rule decision, the project rules check and the receipt written to SQLite. A hook call costs about 2.1 ms more than starting the binary on Linux and 24 ms more on Windows, where most of its cost is the process start. The numbers come from one run on shared runners, and runs differ by more than one run's intervals: the day before, the same code on the same Windows CPU model put the gate 459.5 µs over a direct MCP call, against 616.0 µs here. The results page has p99, calls per second and the caveats.

Limits

The whole list, with the reasons, is under Known limits and risks. The ones to know first:

  • Only calls that pass through the gate are seen. Tools a CLI never shows its hook, such as Codex's hosted web search, are outside it.
  • The CLIs marked experimental at the top have entries and hook adapters that follow each CLI's documentation and have not been checked in a real session. Claude Code and Copilot CLI (1.0.88, on 2026-10-02) have.
  • Argument globs match strings, not meaning: git push* does not match cd repo && git push.
  • Approvals guard against mistakes and prompt injection inside MCP. They do not stop an agent that can already run shell commands as you: it can run derbent approve itself.
  • A receipt export shows its last run unchanged only against a head you kept, and never that nothing was left out of it.
  • A suggestion refuses the shells, launchers and operators it knows, but a text rule can be fooled and those lists cannot be complete, and an allow for a command prefix lets any options through.
  • A handoff's address is a label, not an identity: any agent that can call handoff_take can claim every open handoff addressed to *.
  • Approvals depend on you watching. Unattended, ask means denied after the timeout.
  • Pins trust the first definition they see, including a new tool that an update adds to a pinned server, so name the tools you allow for a server whose updates you do not review.
  • A budget can be passed by the calls in flight at the same moment.
  • CI runs the tests on Windows and Linux and only builds on macOS.

For teams

A team audit trail, with receipts synced off each machine and an export for a SIEM, is an idea, not a plan. If you would use it, say so in this discussion.

Docs

Changes are listed in the changelog. To build, test or send a change, see CONTRIBUTING.md. To report a vulnerability, see SECURITY.md.

Licence

Apache 2.0. See LICENSE.

来源:README.md,提交 1103432

工具

0
工具元数据尚未被收录。

版本历史

1
  1. v1.0.0最新Oct 2, 2026