Skip to main content
Glama
AgentCanon MCP
by touhi13

AgentCanon MCP (agentcanon-mcp)

CI License: MIT

One canonical source of truth for AI coding instructions across OpenAI Codex (AGENTS.md), Cursor (.cursor/rules/*.mdc), Claude Code (CLAUDE.md), and GitHub Copilot (.github/copilot-instructions.md) — with deterministic generation, SHA-256 drift detection, and approval-bound synchronization.


Why AgentCanon MCP?

Modern open-source and enterprise repositories are worked on by contributors using different AI coding agents: OpenAI Codex, Cursor, Claude Code, and GitHub Copilot. Maintaining separate instruction files (AGENTS.md, CLAUDE.md, .cursor/rules/*.mdc, .github/copilot-instructions.md) leads to:

  1. Instruction Drift: Rules updated in AGENTS.md are forgotten in .cursor/rules or CLAUDE.md.

  2. Silent Overwrites: Naive rule generators blindly overwrite manual tweaks made by developers.

  3. Monorepo Complexity: OpenAI Codex supports hierarchical AGENTS.md files per directory, whereas Cursor uses glob-scoped .mdc frontmatter.

AgentCanon MCP solves this by storing typed, validated rules in .agentcanon/rules.yaml and projecting them into each agent's native format through a strict Preview → Approve → Apply transaction.


Related MCP server: mcp-rule-engine

Key Features

  • Canonical Rule Model (.agentcanon/rules.yaml): Typed Zod schema with rule IDs, priorities, categories, glob scopes, directory scopes, and target lists.

  • First-Class OpenAI Codex Support (AGENTS.md): Generates root AGENTS.md as well as nested directory AGENTS.md files (e.g., packages/api/AGENTS.md) when scope.directory is specified.

  • Native Multi-Agent Adapters:

    • OpenAI Codex: AGENTS.md (root & nested directories)

    • Cursor: .cursor/rules/<rule-id>.mdc with YAML frontmatter (description, globs, alwaysApply)

    • Claude Code: CLAUDE.md

    • GitHub Copilot: .github/copilot-instructions.md

  • Transactional Safety (Preview → Approve → Apply):

    • Cryptographically unpredictable planId bound to a SHA-256 fingerprint of both .agentcanon/rules.yaml and target files on disk.

    • Detects manual human edits (conflict_modified_by_user) and pre-existing unmanaged files (conflict_unmanaged_exists), refusing silent overwrites.

    • Protects against path traversal (../) and symlink escape attacks.

  • CI Drift Check CLI: Run npx agentcanon-mcp --check in GitHub Actions to guarantee all agent instruction files stay synchronized with .agentcanon/rules.yaml.


Quick Start

1. Initialize or Import Existing Instructions in Your Repo

npx agentcanon-mcp --init

If your repository already has an AGENTS.md or CLAUDE.md, AgentCanon imports it into .agentcanon/rules.yaml.

2. Sync Rules via CLI (or via MCP Tools)

# Generate and apply all configured agent files
npx agentcanon-mcp --sync-yes

# Verify zero drift in CI
npx agentcanon-mcp --check

3. Configure as an MCP Server

OpenAI Codex / Claude Code / Cursor MCP Configuration (mcp.json):

{
  "mcpServers": {
    "agentcanon": {
      "command": "npx",
      "args": ["-y", "agentcanon-mcp"]
    }
  }
}

Exposed MCP Tools

Tool

Mode

Description

inspect_project

Read

Detects project root, existing AGENTS.md/CLAUDE.md/.cursor files, and canonical status

import_existing_rules

Write Canonical

Bootstraps .agentcanon/rules.yaml from existing instruction files

list_rules

Read

Lists all canonical rules and metadata

upsert_rule

Write Canonical

Creates or updates a rule in .agentcanon/rules.yaml with Zod validation

validate_rules

Read

Checks schema validity, duplicate IDs, contradictory directives, adapter warnings, and token budget

preview_sync

Read / Compute

Computes file diffs, checks SHA-256 manifest for manual edits, and issues a one-time planId

apply_sync

Write Projections

Re-verifies filesystem hashes and atomically writes approved changes


Security & Threat Model

  • Path Traversal & Symlink Defense: Every target path is verified via assertSafeRelativePath and assertNoSymlinkEscape (fs.lstatSync + fs.realpathSync) to ensure writes never escape the repository root.

  • TOCTOU Prevention: apply_sync recomputes the SHA-256 fingerprint of all target files and rejects the plan if any file was modified after preview_sync.

  • No Shell Execution: Rule content is treated strictly as untrusted data; AgentCanon MCP never executes shell commands.


Development & Self-Dogfooding

This repository dogfoods agentcanon-mcp to manage its own AGENTS.md, CLAUDE.md, .cursor/rules/*.mdc, and .github/copilot-instructions.md (verified on every push in .github/workflows/ci.yml).

npm install
npm test
npm run build
npm run dogfood
npm run check:drift

License

MIT © touhi13

Available Tools

7 tools
apply_syncA

Applies a previously previewed sync plan after explicit user approval, verifying no files changed since preview.

Inputs: planId (required), approved (required), projectRoot.

import_existing_rulesC

Bootstraps .agentcanon/rules.yaml from existing AGENTS.md, CLAUDE.md, or creates a starter configuration.

Inputs: projectRoot.

inspect_projectA

Detects repository structure, existing agent instruction files (AGENTS.md, CLAUDE.md, .cursor/rules), and AgentCanon status.

Inputs: projectRoot.

list_rulesC

Lists all canonical rules and metadata from .agentcanon/rules.yaml.

Inputs: projectRoot.

preview_syncB

Computes deterministic agent projections, checks for manual drift/conflicts, and returns an approval-bound planId with file diffs.

Inputs: targets, projectRoot, allowOverwriteConflicts.

upsert_ruleC

Creates or updates a canonical rule inside .agentcanon/rules.yaml with Zod schema validation.

Inputs: rule (required), projectRoot.

validate_rulesC

Validates canonical rules for schema errors, duplicate IDs, formatting conflicts, adapter warnings, and token budget.

Inputs: projectRoot.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 7 tools

    Disambiguation5/5

    Each tool targets a distinct phase of the rule-management lifecycle: inspection, import, listing, single-rule mutation, validation, plan generation, and plan application. The preview_sync/apply_sync pair is explicitly separated by the approval-bound planId contract, so there is no risk of confusing them. No two tools overlap in purpose.

    Naming Consistency5/5

    All seven names use a consistent snake_case verb_noun pattern (inspect_project, list_rules, upsert_rule, validate_rules, preview_sync, apply_sync). Even the longer import_existing_rules follows the same verb-first convention.

    Tool Count5/5

    Seven tools is a tight, well-scoped surface for a rule-canonicalization workflow, and each tool maps to a necessary step (read, import, list, write, check, plan, apply). Nothing appears redundant or missing from the count alone.

    Completeness4/5

    The core lifecycle from inspection through import, editing, validation, and guarded sync is fully covered. Minor gaps remain: there is no delete_rule or get_rule for fine-grained single-rule access, and no rollback/revert operation after apply_sync.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides AI agents with queryable, version-controlled project rules and coding standards. Enables validation, rule-based guidance, and task summaries to keep AI work aligned with your project's conventions without repeating context.
      2
      MIT
    • A
      license
      C
      quality
      D
      maintenance
      Captures code modifications via AST analysis, generates reusable rules, and injects them into AI agent context with version audit and token-budgeted rule retrieval.
      28
      8 npm
      Apache 2.0
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables Claude Code, Cursor, Codex, and Claude Desktop to carry project decisions, rules, bugs, to-dos, and failed approaches across sessions by saving them as lines in a repo file and bringing the relevant ones back on each prompt. It also checks commands and file edits against those saved rules before they run, flagging anything that might break one.
      169 npm
      MIT