Halberd is a proxy for the Model Context Protocol. It runs between an AI assistant and the tools it connects to, reads every JSON-RPC message, and decides: forward it, refuse it, or clean up what comes back. The rules are a YAML file you can read in a minute.
Below is one session with the PostgreSQL rule pack, seven requests from top to bottom. Every verdict on this page comes from the real policy engine, compiled to WebAssembly.
Halberd judges tool calls. Protocol traffic such as initialize is written to the audit log and passed on byte for byte, so the assistant and the server agree on capabilities exactly as they would without it.
The server offers three tools. The rule pack names the same three.
A rule pack is written for one server. This one declares query, list_tables and describe_table, and says what each argument may hold: a type, a length limit, and patterns that must never appear.
Five packs ship with Halberd: PostgreSQL, filesystem, git, GitHub, and a deliberately vulnerable honeypot for demos.
Nothing in the SQL matches a forbidden pattern, so Halberd forwards the request unchanged. The rows that come back include an AWS access key somebody pasted into a notes column.
The response filter recognizes the key and replaces it on the way back. The assistant reads [REDACTED]; the key never enters the model's context.
The scanners know AWS access keys, GitHub tokens and private key blocks. Any other secret passes through.
The same tool, asked to drop the table.
Request 4, tools/call query. Refused: deny_pattern on sql.
The query tool is allowed. This argument is not. The pack forbids DROP TABLE, so Halberd answers the assistant itself with error -32000, and the server never sees the request.
This is argument injection: a permitted tool, called with hostile input. Nine patterns guard the sql argument in this pack, along with an 8,192 byte limit.
A query that reads a file off the database host.
Request 5, tools/call query. Refused: deny_pattern on sql.
The pack lists pg_read_server_files and pg_read_binary_file, so this stops here too.
That is the whole mechanism: Halberd matches patterns somebody wrote down. It does not sandbox the server's filesystem or network, and a function the pack does not list will pass.
The reply hides a terminal escape sequence, and a zero-width character inside a chat role tag. Halberd strips both.
Now read what is left: a plain instruction to ignore previous instructions. Halberd does not detect prompt injection and does not claim to. The threat model rates this coverage as partial.
Put Halberd in your own pipe.
There is no binary release yet. You need Go 1.26 or later.
git clone https://github.com/Builder106/halberd
cd halberd
go build -o bin/ ./cmd/...
./bin/halberd lint policies/mcp-server-postgres.yaml
Build from source
For a remote server, run halberd-http in front of it. The listener has no client authentication, so keep it on loopback unless something else guards the port.
In claude_desktop_config.json, launch halberd-stdio instead of the server. It starts the real server as a child process and sits on its stdin and stdout.