warden-mcp
# warden-mcp
[](https://github.com/ryangurgel/warden-mcp/actions/workflows/ci.yml)
[](pyproject.toml)
[](LICENSE)
**Zero-Trust Policy Firewall & Audit Proxy for AI Agents and MCP Servers**
Put a default-deny policy between your MCP client and SQLite, local documents, fixed HTTPS endpoints, allowlisted commands, or selected tools on trusted upstream MCP servers.

The demo runs a real MCP client against the gateway over stdio. Its deterministic client reads a document containing an instruction override, then submits a scripted write attempt. Warden quarantines the document, blocks the update, reads back the original row and verifies the audit chain.
## Quick start
Requires Python 3.11 or later and [uv](https://docs.astral.sh/uv/).
```sh
uv sync --locked
uv run --locked warden-mcp demo
uv run --locked python examples/seed.py
uv run --locked warden-mcp serve --policy examples/policy.yaml --ledger .warden/audit.sqlite
```
Run `serve` from an MCP client as a stdio subprocess. Replace the example directory with the absolute path to this checkout. Example configuration for clients that use `mcpServers`:
```json
{
"mcpServers": {
"warden": {
"command": "uv",
"args": [
"--directory", "/absolute/path/to/warden-mcp",
"run", "--locked", "warden-mcp", "serve",
"--policy", "examples/policy.yaml",
"--ledger", ".warden/audit.sqlite"
]
}
}
}
```
Call `catalog` to see the configured capability names and kinds. The `invoke` tool takes `capability`, `arguments`, and an optional `approval_id`. These examples work with the seeded policy:
```json
{"capability":"documents","arguments":{"path":"handoff.txt"}}
{"capability":"inventory","arguments":{"query":"SELECT status FROM items WHERE id = 7"}}
{"capability":"inventory","arguments":{"query":"UPDATE items SET status = 'reviewed' WHERE id = 7"}}
```
The update returns `approval_required` and a ticket. From a trusted terminal with access to the same ledger, review the arguments and type `approve` at the prompt. Use `reject` to decline. Resubmit the same capability and arguments with `approval_id` on the original MCP connection. Tickets expire, are scoped to the session, policy and exact JSON arguments, and can start execution once. Both submissions count toward the session budget.
```sh
uv run --locked warden-mcp approve --ledger .warden/audit.sqlite TICKET
uv run --locked warden-mcp verify --ledger .warden/audit.sqlite
uv run --locked warden-mcp replay --ledger .warden/audit.sqlite --session SESSION_ID
```
## Synthetic finance and tax review
An enterprise agent can read sample invoices and propose a review-status update on a ledger entry. [The finance policy](examples/finance_policy.yaml) isolates the two capabilities even though they share a database. All records are fictional, and invoice amounts are stored in minor currency units.
| Capability | Table | Allowed | Human approval |
| --- | --- | --- | --- |
| `invoice_read` | `invoices` | `SELECT` | — |
| `ledger_review` | `ledger_entries` | `SELECT` | `UPDATE` |
Both capabilities omit the `DELETE` rule, so Warden denies it by default. The update changes the review flag on a fictional ledger entry.
```sh
uv run --locked python examples/seed_finance.py
uv run --locked warden-mcp serve --policy examples/finance_policy.yaml --ledger .warden/finance-audit.sqlite
```
Use those policy and ledger paths in the MCP client configuration above. Make these `invoke` calls in the same MCP session:
```json
{"capability":"invoice_read","arguments":{"query":"SELECT invoice_id, currency, amount_minor FROM invoices ORDER BY invoice_id"}}
{"capability":"ledger_review","arguments":{"query":"UPDATE ledger_entries SET review_status = 'reviewed' WHERE entry_id = 1001"}}
```
The first call returns two invoices. The second returns `approval_required` without applying the update. In a separate trusted terminal, review the ticket:
```sh
uv run --locked warden-mcp approve --ledger .warden/finance-audit.sqlite TICKET
```
Resend the same update in the original MCP session with the ticket as a top-level `approval_id`. Then read back the reviewed entry and try a delete:
```json
{"capability":"ledger_review","arguments":{"query":"SELECT review_status FROM ledger_entries WHERE entry_id = 1001"}}
{"capability":"ledger_review","arguments":{"query":"DELETE FROM ledger_entries WHERE entry_id = 1001"}}
```
The readback returns `reviewed`. The delete returns `denied`. Use `uv run --locked warden-mcp replay --ledger .warden/finance-audit.sqlite` to see the approval and denial events.
## Policy and controls
[The example policy](examples/policy.yaml) allows document reads and SQLite `SELECT`, requires approval for `UPDATE`, and denies `INSERT` and `DELETE`. Missing SQL rules default to deny. Operator-controlled relative paths resolve from the policy directory. Edit the YAML and restart the server to apply changes.
| Kind | Input | Controls |
| --- | --- | --- |
| `sql` | `{"query":"…"}` | SQLGlot parses one SQLite statement. SQLite independently applies a table and function allowlist through its authorizer. Read access uses a read-only connection. |
| `file` | `{"path":"…"}` | Bounded UTF-8 reads inside a resolved root. Keep that root and its parent directories outside the agent's write access. |
| `command` | `{"command":"…"}` | Bash AST for syntax review on all platforms. Warden executes a configured absolute binary with an exact allowlisted argument vector and without a shell. Use a trusted binary with bounded runtime and no background children. |
| `http` | `{}` for GET, optional `{"json":…}` otherwise | One configured HTTPS URL and method, certificate verification, no redirects or inherited HTTP proxies. Configure sites you trust. Methods other than GET are always classified as writes. |
| `mcp` | Upstream tool argument object | A configured local executable is launched over stdio for each call. Warden routes to one configured upstream tool and applies policy to the operator-declared effect. |
Additional YAML capability examples, with paths to be supplied by the operator:
```yaml
version_check:
kind: command
executable: /absolute/path/to/git
arguments: [[--version]]
effect: read
decision: allow
published_status:
kind: http
url: https://example.org/status
method: GET
effect: read
decision: allow
remote_summary:
kind: mcp
executable: /absolute/path/to/upstream-server
args: []
upstream_tool: summarize
effect: read
decision: approval
```
- **Untrusted content.** Text values from backends are scanned for instruction override and role impersonation patterns. Quarantine withholds the response and marks the session. In `label` mode, the response is returned as untrusted alongside the detection. Any detection raises otherwise permitted writes to human approval for the rest of the session. Heuristics can miss novel, encoded or multimodal instructions.
- **Budgets.** One stdio process is one session. Warden serializes invocations, counts attempts including policy denials and charges configured integer credits per capability. Credits represent operator-defined weights. Budget state resets when the client starts a fresh process. The client host controls process creation.
- **Audit and replay.** A SQLite ledger chains canonical JSON events with SHA-256. Execution is logged before a backend can act. A crash may leave a started event without a terminal outcome. Replay verifies and prints recorded events without executing tools. The events contain input/output hashes and decision metadata. Pending approval records contain raw arguments for operator review. Warden clears them after a decision or when a later approval operation or server startup cleans up expired tickets. Give the ledger directory OS-level access controls and use `verify --expected-head HASH` with a separately retained, current checkpoint to detect truncation or a rewritten chain.
## Trust boundary
Run Warden under an account the agent cannot impersonate. Protect policy, ledger, approval CLI, trusted executables and backend access independently using OS controls. An MCP client that can reach the same database, filesystem, endpoints or tools directly can bypass the gateway. SQLite files and configured upstreams are trusted operator assets. Upstream tools and command binaries can perform side effects according to their own permissions. The gateway scopes access to configured capabilities, with no row-level SQL policy, MCP resource or prompt forwarding, or native model billing integration. Store the ledger on local storage. For HTTP or MCP actions whose response failed, review the upstream outcome before retrying.
## Architecture decisions
- [ADR 001 — Layer SQLite authorization](docs/adr/001-defense-in-depth-sql.md)
- [ADR 002 — Chain audit events in local SQLite](docs/adr/002-hash-chained-sqlite-ledger.md)
- [ADR 003 — Quarantine suspicious output and raise write approval](docs/adr/003-untrusted-content-quarantine.md)
## Development
```sh
uv sync --locked
uv run --locked ruff check .
uv run --locked ruff format --check .
uv run --locked pytest
uv build
```
Regenerate the checked-in 8-second cover from the live demo with `uv run --locked python scripts/render_demo.py`. See [SECURITY.md](SECURITY.md) for reporting guidance. Released under the [MIT License](LICENSE).
TDQS
Scored across 2 tools
The two tools are clearly distinct: catalog is a read-only discovery operation and invoke is an execution operation. An agent cannot reasonably confuse listing capability names with invoking one.
Both names are single lowercase verbs in a consistent style, forming a predictable discover-then-act pair. They omit an explicit object noun (e.g. list_capabilities, invoke_capability), but the pattern is uniform.
Two tools is below the typical 3-15 range, but for a capability gateway the discover/execute pair is the minimal complete surface and each tool clearly earns its place. Slightly thin rather than excessive.
Discovery plus invocation covers the core loop, but there is no way to inspect a capability's expected arguments/schema, view policy details, or query/verify the audit records that invoke produces. These are notable gaps that could cause failed invocations.