AgentCanon MCP
Provides canonical rule projection into GitHub Copilot's .github/copilot-instructions.md file, keeping Copilot instructions synchronized with the canonical rule model.
Provides canonical rule projection into OpenAI Codex instruction files, generating root and nested AGENTS.md files according to rule scopes and targets.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@AgentCanon MCP preview syncing my canonical rules to AGENTS.md, CLAUDE.md, and Cursor rules"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
AgentCanon MCP (agentcanon-mcp)
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:
Instruction Drift: Rules updated in
AGENTS.mdare forgotten in.cursor/rulesorCLAUDE.md.Silent Overwrites: Naive rule generators blindly overwrite manual tweaks made by developers.
Monorepo Complexity: OpenAI Codex supports hierarchical
AGENTS.mdfiles per directory, whereas Cursor uses glob-scoped.mdcfrontmatter.
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 rootAGENTS.mdas well as nested directoryAGENTS.mdfiles (e.g.,packages/api/AGENTS.md) whenscope.directoryis specified.Native Multi-Agent Adapters:
OpenAI Codex:
AGENTS.md(root & nested directories)Cursor:
.cursor/rules/<rule-id>.mdcwith YAML frontmatter (description,globs,alwaysApply)Claude Code:
CLAUDE.mdGitHub Copilot:
.github/copilot-instructions.md
Transactional Safety (
Preview → Approve → Apply):Cryptographically unpredictable
planIdbound to a SHA-256 fingerprint of both.agentcanon/rules.yamland 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 --checkin 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 --initIf 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 --check3. 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 |
| Read | Detects project root, existing AGENTS.md/CLAUDE.md/.cursor files, and canonical status |
| Write Canonical | Bootstraps |
| Read | Lists all canonical rules and metadata |
| Write Canonical | Creates or updates a rule in |
| Read | Checks schema validity, duplicate IDs, contradictory directives, adapter warnings, and token budget |
| Read / Compute | Computes file diffs, checks SHA-256 manifest for manual edits, and issues a one-time |
| Write Projections | Re-verifies filesystem hashes and atomically writes approved changes |
Security & Threat Model
Path Traversal & Symlink Defense: Every target path is verified via
assertSafeRelativePathandassertNoSymlinkEscape(fs.lstatSync+fs.realpathSync) to ensure writes never escape the repository root.TOCTOU Prevention:
apply_syncrecomputes the SHA-256 fingerprint of all target files and rejects the plan if any file was modified afterpreview_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:driftLicense
MIT © touhi13
Available Tools
7 toolsapply_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
Scored across 7 tools
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.
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.
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.
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
Related MCP Connectors
Git-native policy layer for AI agents: check_action verdicts against rules approved via PR.
Preventive human-approval write-gate for AI agents: writes commit only after a human approves.
Enforces architectural invariants and code quality rules inside your AI agent's edit loop.
Pre-execution governance for AI agents. Deterministic PASS/FAIL/REVIEW verdicts, replayable proof.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides 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.2MIT
- AlicenseCqualityDmaintenanceCaptures code modifications via AST analysis, generates reusable rules, and injects them into AI agent context with version audit and token-budgeted rule retrieval.288 npmApache 2.0
- AlicenseNot gradedqualityCmaintenanceEnables auditing and drafting of AI agent files (CLAUDE.md, AGENTS.md, Cursor rules) and turning project descriptions into full build specs, with local and API-based tools.47 npmMIT
- AlicenseNot gradedqualityAmaintenanceEnables 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 npmMIT