Useful access, with limits you choose. Halberd checks an AI assistant's tool requests against your policies before letting them through.
You ask an AI assistant to look up ten student records. So far, so useful. But the same database tool can receive a command to erase an entire table. Who checks which request gets through?
Halberd sits between the assistant and its connected tools. You choose the rules: which tools are permitted, which commands are forbidden, and which sensitive values should be removed from responses. Halberd applies those rules as requests and responses pass through it.
Every tool call is checked before it leaves the proxy. A refused call never reaches the MCP server.
Here are two requests checked against the bundled PostgreSQL policy. SELECT id, name FROM students LIMIT 10 reaches the database tool unchanged. DROP TABLE students matches a forbidden-command pattern, so the assistant receives an error instead. Both decisions are sent to the audit bus for recording.
Developer details
Halberd is a reverse proxy for the Model Context Protocol (MCP), the protocol AI assistants use to call connected tools. It supports HTTP and local stdio transports.
- The PostgreSQL bundle declares the
querytool, a string-valuedsqlargument, an 8,192-byte limit, and forbidden SQL patterns. - The policy engine checks the tool and arguments. A matched pattern produces a
deny_patternviolation. - The HTTP proxy records the decision, then either forwards the request body unchanged or returns JSON-RPC error
-32000to the assistant. That protocol error travels inside an HTTP200response. - Response filtering is a separate step. Configured filters remove escape sequences and redact recognized secret patterns in JSON-RPC results, including HTTP event streams.
These decisions come from the configured rules. Halberd does not create an operating-system sandbox. See the firewall architecture for the enforcement boundaries and the policy DSL to write your own rules.
Try the same requests: Open the console, choose the PostgreSQL pack, and compare the two queries. The console runs the Go policy engine in your browser through WebAssembly, so you can inspect a decision without installing the proxy.
Watch it work
Every challenge resolves to one of three protocol verdicts:
| Verdict | Disposition | Client response |
|---|---|---|
| Refused | Blocked | Synthetic JSON-RPC error (-32000) before reaching upstream |
| Allowed | Forwarded | Request forwarded to upstream tool server unchanged |
| Amended | Sanitized | Response rewritten to redact secrets and strip control characters |
A DROP TABLE under the PostgreSQL pack, refused before forwarding:
Amended: recognized secrets redacted from a tool reply
An assistant's tools can read files, run queries, and return data that influences its next action. These are the threats Halberd's policies address, including the I/O controls still on the roadmap:
| # | Threat | What happens |
|---|---|---|
| T1 | Tool poisoning | A compromised tool server returns hidden commands designed to hijack the AI's next action |
| T2 | Argument injection | An attacker tricks the AI into running destructive commands (such as deleting database tables or running dangerous shell scripts) |
| T3 | Unauthorized file access | A tool attempts to read private system files or access restricted networks |
| T4 | Permission creep | A connected server silently introduces new, unvetted tools in the middle of an active session |
| T5 | Secret exfiltration | A tool response accidentally leaks API keys, passwords, or encryption keys back to the AI model |
Halberd checks configured T2 rules, denies undeclared tools (T4), and can strip control characters and recognized secrets from tool results (parts of T1 and T5). It does not detect general prompt injection, enforce a filesystem or network sandbox (T3), or guarantee that every secret format is recognized.
Pre-compiled binary releases for Linux and macOS (amd64 and arm64) are available on GitHub Releases. Each release archive includes halberd, halberd-http, halberd-stdio, halberd-honeypot, the example policy, and bundled rule packs.
Verify the downloaded archive against the published checksums:
sha256sum -c checksums.txtTo build from source, install 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| Pack | Checks | Note |
|---|---|---|
mcp-server-postgres.yaml |
Denies listed SQL patterns and scans results for recognized secrets | Review it against your database permissions; it is not a read-only SQL policy |
mcp-server-filesystem.yaml |
Denies listed path patterns and scans returned text for recognized secrets | Array-arg tools (read_multiple_files, edit_file) are denied; the rules do not resolve symlinks or enforce a filesystem root |
mcp-server-git.yaml |
T2 (--upload-pack=…-style long-opt smuggling in ref/branch names; path traversal in repo_path), T5 |
State-mutating tools (commit, add, reset, init) denied by default |
mcp-server-github.yaml |
Checks configured owner values, repo-name patterns, and response secrets | Edit your-org before use. Destructive tools such as delete_repository and transfer_repository are not listed |
halberd-honeypot.yaml |
Demo cases for denied inputs and secret redaction | Matched bundle for cmd/halberd-honeypot; demo-only |
Halberd ships with a deliberately-vulnerable MCP server,
cmd/halberd-honeypot, whose tool outputs
are the threats themselves. Pair it with halberd-stdio and the
matched bundle for a one-command end-to-end demo:
go build -o bin/ ./cmd/...
bin/halberd-stdio \
--policy policies/halberd-honeypot.yaml \
--audit halberd.jsonl \
-- bin/halberd-honeypotPipe in a tools/call for execute_sql with DROP TABLE, or read_file
with ../../etc/passwd, or list_users (the response carries fake
AWS / GitHub / RSA secrets) — and watch Halberd block, redact, and audit
each one. See cmd/halberd-honeypot/README.md
for the full threat-coverage table.
▶ Watch it run — 30s terminal cast: DROP TABLE refused, secrets redacted, audit log captured
./bin/halberd-http \
--policy policies/mcp-server-postgres.yaml \
--target http://localhost:8080 \
--listen 127.0.0.1:9090 \
--audit halberd.jsonlPoint your MCP client at http://127.0.0.1:9090 instead of the postgres
server. Halberd queues each tools/call decision for the audit log and
reports dropped events if the queue fills. Try a DROP TABLE — Halberd
returns a JSON-RPC error before the request reaches postgres.
The listener binds to loopback by default. Requests carrying a cross-origin Origin header are rejected. If you bind it to a network interface, protect access at the network boundary; Halberd has no client authentication.
Drop halberd-stdio into the host's MCP server config in place of the
real server command. For Claude Desktop, edit
~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"postgres": {
"command": "/usr/local/bin/halberd-stdio",
"args": [
"--policy", "/etc/halberd/postgres.yaml",
"--audit", "/var/log/halberd/postgres.jsonl",
"--",
"mcp-server-postgres", "--conn-string", "postgresql://..."
]
}
}
}Restart Claude Desktop. Every JSON-RPC message between Claude and
mcp-server-postgres now flows through Halberd. Argument-injection
attempts (DROP TABLE, statement chaining via ; --, etc.) come back
to Claude as JSON-RPC errors that the model can reason about, and the
upstream server never sees the blocked payload.
version: 1
server: mcp-server-postgres
tools:
- name: query
arguments:
sql:
type: string
max_length: 8192
deny_patterns:
- '(?i)\bdrop\s+(table|database|schema)\b'
- ';\s*--' # statement chaining
defaults:
unknown_tool: deny # T4: block tools not in this bundle
unknown_method: log_and_passFull reference: docs/policy-dsl.md.
| Phase | Status | Outcome |
|---|---|---|
| P1 — HTTP reverse proxy + audit bus | implemented | halberd-http forwards JSON-RPC and logs request decisions |
| P2 — Policy engine, deny-pattern blocking, T2 + T4 coverage | implemented | YAML bundles, regex denylist, unknown-tool guard |
| P3 — stdio transport | implemented | halberd-stdio wraps local MCP servers over line-delimited JSON-RPC |
| P4 — Response inspection | implemented | Inspect JSON-RPC result strings, including SSE events; strip selected control characters and redact recognized AWS, GitHub, and private-key formats |
| P5 — Rule packs + hardening | implemented | Bundles for mcp-server-{filesystem,git,github,postgres} and per-pack tests |
CI records policy-engine benchmarks, but does not enforce a latency or throughput limit. Run go test -bench=. -benchmem ./internal/policy to measure your build and hardware.
cmd/halberd-http— the reverse-proxy binarycmd/halberd-stdio— the stdio MITM wrapper binarycmd/halberd— operator CLI (halberd lint …)cmd/halberd-honeypot— deliberately-vulnerable MCP server for demos and integration testsinternal/policy— IO-free policy engineinternal/jsonrpc— JSON-RPC 2.0 envelope + error synthesisinternal/audit— non-blocking audit bus → JSONLinternal/transport/http—httputil.ReverseProxywrapperinternal/transport/stdio— bidirectional JSON-RPC pipe with policy MITMpolicies/— rule packs (data, not code)
-
mcp-scan— staticanalysis of MCP server source. Complementary to Halberd (static vs. runtime).
-
Cloudflare AI Gateway / Portkey — LLM-side proxies, inspect prompts and
completions, not tool-call envelopes. Different layer.
-
Microsoft RAMPART — fuzzing harness for agentic security testing.
Test-time, not prod-time.
See CONTRIBUTING.md. The "out of scope" list near the bottom is worth reading before opening a PR.
MIT. See LICENSE.




