Skip to main content
Glama

qedra

CI License: MIT ss1738/qedra MCP server

qedra checks coding-agent tool calls before execution. It provides a local MCP server, a Claude Code permission hook, and a Python adapter for function-calling loops. The gate blocks selected destructive Git, shell, and file operations and can export signed receipts of recorded decisions.

Status: experimental, single-maintainer software. Shell checks are bypassable heuristics. The executor is not a sandbox, and receipts do not independently prove that commands ran or that the operator recorded every action.

Install from this repository

Requires Python 3.10 or later, Git, and Bash for shell execution.

git clone https://github.com/ss1738/qedra.git
cd qedra
python3 -m venv .venv
. .venv/bin/activate
pip install -e '.[mcp]'
qedra-mcp

The MCP integration uses the MCP Python SDK 1.x (mcp>=1.0,<2). Installing from this checkout avoids assuming that an unreleased repository change is on PyPI. The base package can be installed with pip install -e . without MCP support.

Related MCP server: aperion-shield

What the policy checks

Surface

Check

Limit

Structured Git actions

Force-push, hard reset, and rebase against configured protected branches

z3 checks a finite policy model, not the Python parser, Git itself, or every history-changing command

Shell commands

Patterns for repo/home/root deletion, secret exposure, cloud metadata access, reverse shells, and persistence

Default allow; obfuscation and unrecognized forms can bypass the checks

File writes

Recognized secret values and empty .github/workflows/ content

Does not analyze general source changes or validate workflow semantics

Optional devops preset

Patterns for selected infrastructure, database, and package deletion commands

Off by default; heuristic

Protected branches default to main, master, and release. A structured Git call with an unresolved force-push destination is refused for human review. Global Git options such as -C are refused by the executor. Normal arguments are parsed with shlex, so quoted commit messages remain intact.

A write-path check refuses paths outside the workspace. Shell commands still run with the gate process's filesystem access, environment, credentials, and network permissions. Put the process inside a separately configured OS/container sandbox; a working directory alone does not provide isolation. Do not expose the server to untrusted callers with access to your personal credentials.

Read THREAT_MODEL.md and SECURITY.md before use.

MCP client configuration

After installation, merge this entry into your client's mcpServers object. Use an absolute executable path if the client does not inherit your virtualenv PATH.

{
  "mcpServers": {
    "qedra": {
      "command": "/absolute/path/to/qedra/.venv/bin/qedra-mcp",
      "env": {
        "GUARDRAIL_WORKSPACE": "/absolute/path/to/working/repo"
      }
    }
  }
}

Tools: run_shell, write_file, git, audit_log, policy_info, and session_receipt. Calls made through other tools bypass this gate.

Variable

Meaning

GUARDRAIL_WORKSPACE

Working repository; defaults to ./workspace

GUARDRAIL_AGENT_ID

Receipt identity label; default agent

GUARDRAIL_POLICY_ID

Policy label; default default-policy in MCP, claude-code in the hook

GUARDRAIL_PRESET

Comma-separated optional presets, currently devops

GUARDRAIL_POLICY_SPEC

Path to JSON policy data

GUARDRAIL_SIGNING_KEY

MCP only: hex-encoded 32-byte Ed25519 seed; otherwise an ephemeral key is generated

GUARDRAIL_SIGNING_KEY_FILE

Attestation CLI default key path; defaults to ~/.qedra/signing_key

GUARDRAIL_AUDIT_LOG

Optional JSONL decision log; use a separate file per MCP server/session

GUARDRAIL_ALERT_URL

Optional webhook; sends action kind and generic reason, not raw commands

GUARDRAIL_ZK

MCP only: 1, modp, or ec enables experimental Git-policy proofs

Keep audit files, signing keys, policy data, and the gate source inaccessible to the agent. Audit files contain raw actions, including blocked secret values. New audit files are created with mode 600; existing file permissions are preserved. Hook log transactions use POSIX file locks; do not share one log between MCP servers or mix MCP and hook writers. Audit failures are reported but do not stop the gate, so a failed log sink can leave the on-disk trail incomplete.

Claude Code hook

qedra-hook --print-config

Merge the printed hook into .claude/settings.json. It matches Bash by default; use Bash|Write|Edit to include file operations. Edit checks replacement text, not the final whole file. An empty replacement in a workflow can therefore be blocked even when the edit would leave other content in place.

The hook denies BLOCK, asks the user for ESCALATE, and permits ALLOW. Internal errors fail open: malformed input or invalid configuration can allow a call. Errors are printed to stderr. This is an availability tradeoff, not a fail-closed security boundary.

The hook runs before a tool. Its audit entries record permission decisions with executed=false; they do not observe the eventual command outcome.

export GUARDRAIL_AUDIT_LOG=/absolute/private/path/session.jsonl
# Run your Claude Code session, then attest its permission-decision log:
qedra-attest "$GUARDRAIL_AUDIT_LOG" --policy-id claude-code \
  --agent-id my-agent --out receipt.json
qedra-verify receipt.json --policy-id claude-code --pin-key PUBLIC_KEY_HEX

Replace PUBLIC_KEY_HEX with the public key printed by qedra-attest. If you used custom policy data or presets, pass the same --policy-spec / --preset to attestation and supply that policy data to the verifier. A verifier must obtain its expected public key and policy through a trusted channel.

Python tool adapter

from qedra.control_plane import ControlPlane, Policy
from qedra.tool_gate import ToolGate, openai_tools

gate = ToolGate("/path/to/repo", control_plane=ControlPlane("agent", Policy("local")))
tools = openai_tools()  # OpenAI Chat Completions schema; not Responses format
result = gate.handle("write_file", {"path": "notes.txt", "content": "hello"})
receipt = gate.receipt()

anthropic_tools() returns Anthropic tool definitions. The adapter refuses unknown tools, missing arguments, and non-string input fields. It uses the same executor as MCP and inherits its isolation limits.

Receipts and policy data

qedra-policy init --protected main,release --out policy.json
qedra-policy show policy.json --policy-id local
qedra-redact receipt.json --out redacted.json --witness witness.json
qedra-verify redacted.json --witness witness.json --pin-key PUBLIC_KEY_HEX
qedra-serve --policy-id local --host 127.0.0.1

Verification checks policy identity, the signed chain, and policy verdicts for disclosed actions. Redacted entries without a disclosure witness or supported ZK proof have no verdict soundness check. Identity requires a pinned key or a trusted registry. A signer can omit actions or create an entirely different compliant trace, so a valid receipt is not independent evidence of execution or completeness. Unsigned audit chains cannot detect tail truncation or a complete recomputation. See the receipt trust model.

Both ZK backends are experimental custom cryptography without an external audit. They cover only a projection of selected Git actions, not shell/file operations or execution. See docs/ZK_ROADMAP.md.

Development and validation

pip install -e '.[mcp,dev]'
python3 -m pytest -q
python3 -m ruff check qedra
python3 demo_receipt.py
python3 demo_attest.py
python3 demo_claude_hook.py
python3 integrations/demo_mcp.py

demo_claude_hook.py supplies synthetic payloads to the real hook classifier; it does not launch Claude Code or execute the proposed commands. The MCP demo uses an actual local stdio client/server connection. No API key is needed for either. demo_hijack.py is a separate opt-in API experiment requiring an Anthropic key and an explicitly selected model.

realworld_test.py and scripts/expanded_realworld.py fetch changing GitHub workflow samples and classify command text without executing it. Historical claims of 2,836 / 2,848 / 3,790 commands do not have a frozen corpus and result artifact in this repository. They are not current reproducible performance baselines. Neither script measures adversarial detection or end-to-end security.

The z3 proof is a check of a manually modeled sub-policy. It does not verify the Python implementation. Tests complement the model but do not prove the absence of bugs. Run Rust/cargo commands only on an appropriately isolated build host.

Reporting issues

For bugs, include the exact tool call, configuration without secrets, observed verdict, and expected behavior. See SECURITY.md for sensitive reports.

Maintained by Satyawan Singh (@ss1738). MIT licensed.

Available Tools

6 tools
audit_logA

Return the tamper-evident audit chain of every guardrail decision so far.

Inputs: no named parameters. Returns: result

gitA

Execute Git in the workspace after structured branch-policy checks. Use this rather than run_shell for Git operations. Protected-branch force pushes, hard resets and rebases are blocked; unresolved force destinations are refused for human review. Quoting is preserved. Returns truncated stdout/stderr or a refusal prefixed with ⛔; it is not a proof of success.

Inputs: args (required). Returns: result

policy_infoA

Report the exact ruleset being enforced: the committed policy id and root (content hash), the protected branches, and any opt-in presets/extra patterns. A relying party can hold the same spec and confirm the receipt's policy root matches, so 'the gate enforces this policy' is checkable, not a promise.

Inputs: no named parameters. Returns: result

run_shellA

Execute a Bash command after heuristic policy checks. Use for build, test or inspection commands, not file writes or structured Git operations. Returns truncated stdout/stderr, or a refusal prefixed with ⛔. BLOCK and ESCALATE decisions are not executed. Shell execution is not sandboxed; passing a check does not establish that a command is safe.

Inputs: cmd (required). Returns: result

session_receiptA

Export a signed statement of recorded decisions. Verification checks its signature, chain and disclosed policy verdicts, not execution or completeness. Use an independently obtained policy and pinned key for attribution.

    redact=True strips every raw action (commands, file contents, branches) before returning. In
    zk-mode (GUARDRAIL_ZK=1) git-branch actions stay provably in-policy via their zero-knowledge proof
    even when redacted; other actions keep integrity + authenticity only.

Inputs: redact. Returns: result

write_fileA

Create or overwrite one workspace file after policy checks. Creates parent directories as needed. Recognized secret values and empty workflow writes are blocked. Returns a write summary or a refusal prefixed with ⛔. This is a whole-file replacement; read and preserve needed content first.

Inputs: path (required), content (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4/5.0

    Scored across 6 tools

    Disambiguation4/5

    The execution tools are clearly separated: run_shell for commands, git for structured Git, and write_file for whole-file writes. audit_log, policy_info, and session_receipt all concern guardrail evidence, but their descriptions distinguish raw audit chain, policy specification, and signed receipt well enough for selection.

    Naming Consistency3/5

    All names use snake_case, which keeps them readable, but the conventions are mixed: run_shell and write_file are verb_noun, git is a bare noun, and audit_log, policy_info, and session_receipt are noun phrases. The set is not chaotic, but it lacks a single predictable pattern.

    Tool Count5/5

    Six tools are well-scoped for a guardrailed workspace server. Each tool covers a distinct capability: shell execution, file writing, Git operations, audit export, policy inspection, and signed receipts.

    Completeness4/5

    The guardrail lifecycle is well covered with execution, policy disclosure, audit chain, and signed receipts. Minor gaps exist around dedicated file reading/deletion, but run_shell can inspect files and perform many workarounds, so this is not a dead end.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Local guardrails for AI coding agents. Checks each tool call from Claude Code, Cursor, Codex and MCP servers, and stops or asks before destructive ones run (DROP TABLE, rm -rf, force-push, unscoped UPDATE/DELETE). Free, runs on your machine, source-available under the Elastic License 2.0.
      16
      13
      Elastic 2.0
    • A
      license
      A
      quality
      C
      maintenance
      A cooperative guardrail for AI agents that blocks destructive shell commands, SQL statements, or cloud operations until a human approves them out-of-band, with a tamper-evident local ledger.
      4
      AGPL 3.0
    • A
      license
      A
      quality
      C
      maintenance
      Enables AI coding agents to avoid irreversible mistakes by intercepting risky deletions, overwrites, and commands before execution, applying path, pattern, and blast-radius safeguards with quarantine backups.
      3
      MIT