Skip to main content
Glama
README.md
<!-- mcp-name: io.github.gamai-io/agents-md-guard -->
# agents-md-guard

[![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Blocks silent weakening of `AGENTS.md` / `CLAUDE.md` / `.cursorrules` by an agent.

The problem is measured, not hypothetical: GitHub has roughly 719,000 repositories with
agent instruction files, and in the 100 most-starred repositories 33 have at least one
commit to those files authored or co-authored by an agent
([Sharma, 2026](https://homes.cs.washington.edu/~reshabh/posts/exponential-rise-of-agent-instruction-files.html)).
A one-word change - "MUST ask" to "may ask" - rewrites what the agent is allowed to do,
and prose diffs rarely get read.

## What it does

On every push or pull request it checks:

1. which instruction files changed;
2. whether the commit carries `Human-Reviewed-By: Name <email>`;
3. whether a line with a normative keyword (`MUST`, `NEVER`, `ALWAYS`, `FORBIDDEN`,
   `OBAVEZNO`, `NIKAD`, `NE SMIJE` ...) was removed or rewritten.

Unapproved changes are blocked. Approved ones pass, with the removed rules printed in the log.

## Use

```yaml
# .github/workflows/agents-md.yml
name: agents-md-guard
on: [push, pull_request]
jobs:
  guard:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - uses: gamai-io/agents-md-guard@v1
        with: { base: origin/main }
```

Local check before committing:

```bash
python3 agents_md_guard.py --staged
```

## MCP server

The same check is available as an MCP tool, so an agent can inspect the rules it is
being given before it acts. Stdlib only, no SDK, JSON-RPC 2.0 over stdio
(protocol `2025-06-18`).

```bash
pip install agents-md-guard
```

```json
{
  "mcpServers": {
    "agents-md-guard": {
      "command": "agents-md-guard-mcp"
    }
  }
}
```

| tool | input | returns |
| --- | --- | --- |
| `agents_md_check` | `{path}` or `{text}`, or `{repo, rev/base/staged}` for the diff gate | findings: `no_rules`, `weak_rule`, `negation_conflict`, `duplicate_rule`, `long_rule`, `too_many_rules`, `unapproved_rule_file`, `empty_file` |
| `agents_md_rules` | `{}` | guarded file names, normative keywords (EN + BS), the approval trailer, lint codes, exit codes |
| `agents_md_fix_suggestions` | `{path}` or `{text}` | one concrete rewrite hint per finding, with the offending line |

`agents_md_check` is deterministic and offline: a permissive bullet ("you may send mail")
is a `weak_rule`, two rules over the same action where one is negated is a
`negation_conflict` (an error, so `ok` is false), and a file with zero normative
keywords is `no_rules`.

## Tests

`python3 -m pytest -q tests` builds throw-away git repositories and asserts the
exit codes: an unrelated commit passes, an unapproved weakening is blocked, an
approved one passes and prints the rule it removed, `.github/copilot-instructions.md`
is guarded, and the forty-zeros `event.before` of a first push is not a usage error.

## What it is not

It does not verify at runtime that the agent obeyed a rule. This is a diff-time gate on the
rules themselves; runtime proof of an action is a different artefact (see
[gamai-io/gama-mandate](https://github.com/gamai-io/gama-mandate) for signed receipts).

MIT.

TDQS

A3.7/5.0

Scored across 3 tools

Disambiguation4/5

agents_md_check and agents_md_fix_suggestions operate on the same input and both produce lint findings, so an agent could initially hesitate between them. The descriptions do resolve it (findings vs. per-finding rewrite hints), and agents_md_rules is clearly a static reference lookup, so boundaries are mostly clear.

Naming Consistency5/5

All three tools share the same 'agents_md_' prefix and snake_case style, with short action-oriented suffixes (check, rules, fix_suggestions). The pattern is immediately predictable and scannable.

Tool Count5/5

Three tightly scoped tools for a linter/guard server: run the lint, fetch the rule reference, get fix hints. Nothing feels padded or missing at the surface level.

Completeness4/5

The core lifecycle (diagnose -> understand rules -> remediate) is covered, including the diff-gate mode via check. Minor gaps: no tool to actually apply fixes or to configure/initialize a guard file, so agents must edit files themselves.