Skip to main content
Glama

🛡️ Edit Math Supervisor (MCP Server)

An implementation of the Edit Approval State Machine (EASM)

A stateful gatekeeper for AI-driven code editing

Donate PyPI

Overview

This project implements a Model Context Protocol (MCP) server that acts as an architectural gatekeeper between an AI coding agent and the file system.

Its purpose is simple:

An AI is not allowed to edit code unless it has demonstrated awareness of the consequences and obtained explicit human approval.

The server enforces this rule procedurally, not heuristically.


Related MCP server: Aedile

Why this exists

Modern AI coding assistants can generate and apply code changes faster than humans can reliably reason about their impact.

This creates a dangerous asymmetry:

  • the AI can act immediately

  • the human can only review after the fact

In practice, this leads to:

  • silent breaking changes

  • accidental dependency violations

  • refactors without understanding downstream effects

This project explores a different model.

The AI must stop. Explain. Ask. And wait.

Only then is it allowed to modify code.


🧠 Philosophy: Architectural Control over AI Action

This project is intentionally not focused on making AI “smarter”.

Instead, it explores a different question:

What architectural constraints are required when an AI system is allowed to act on real code?

Most AI coding tools optimize for fluency and speed. This project optimizes for procedural awareness.

The core assumption is simple: AI systems do not lack intelligence —
they lack structural incentives to pause, explain, and verify.

The Edit Approval State Machine introduces such a structure.

It forces the AI to:

  • stop before acting

  • externalize its assumptions

  • acknowledge dependencies

  • wait for explicit human intent

In this model, the human provides intent and responsibility. The AI provides execution and analysis.

The result is not “better code generation”, but controlled code modification.


The core idea: Edit Approval State Machine (EASM)

At the heart of this server is the Edit Approval State Machine
a security and control pattern for AI-driven code edits.

Each edit target exists in one of three states:

  • NONE
    No approval. Editing is forbidden.

  • PENDING
    Dependencies have been analyzed.
    The system is waiting for explicit human confirmation.

  • APPROVED
    Permission granted.
    A single safe edit is allowed.

State transitions are enforced by the server. The AI cannot skip steps, self-approve, or persist approval silently.


Human confirmation token

For any edit that is potentially non-trivial — for example:

  • detected dependencies

  • renaming

  • declared breaking changes

the server requires an explicit human confirmation token.

By default, this token is the literal string: ок

The token:

  • must come from the user

  • is validated by the server

  • cannot be generated or assumed by the AI on first pass

This creates a hard human-in-the-loop boundary.


What this project is (and is not)

This project is:

  • a procedural safety layer for AI coding agents

  • a stateful MCP server enforcing edit discipline

  • an experiment in AI control, not AI intelligence

This project is not:

  • ❌ a linter

  • ❌ a static analyzer

  • ❌ a sandbox

  • ❌ a code correctness verifier

The goal is not to prove code correctness.

The goal is to prevent unreviewed action.


Supported analysis

The server performs lightweight dependency extraction using:

  • Python AST (ast)

  • Tree-sitter for JavaScript, TypeScript, and HTML

The analysis is intentionally conservative and incomplete. It is used to force awareness and explanation, not to model full semantics.


Threat model

This project assumes:

  • AI agents optimize for task completion speed

  • AI agents may skip reasoning steps if not explicitly blocked

  • silent failures are more dangerous than slow workflows

As a result, the system is designed to fail closed.


Typical workflow

  1. AI requests dependency analysis for a target

  2. Server returns detected dependencies and revokes edit access

  3. AI explains risks and plan to the user

  4. User explicitly confirms by typing ok

  5. Server grants approval for a single edit

  6. Approval is reset after commit

Any deviation resets the process.


Origin

This project and the Edit Approval State Machine (EASM) pattern were created by Annenkov Yuriy in 2025.

The goal was to explore architectural safeguards for AI-assisted software development, especially in environments where correctness and trust matter.


🆕 What's New in v1.5.0

  • Python Support: Native AST parsing for Python files.

  • HTML Support: Dependency detection in <script> tags and event handlers.

  • 2-Step Handshake: New security mechanism. The server now requires a specific token ('ok') to confirm dangerous edits, preventing the AI from "hallucinating" user consent.

  • Renaming Detection: Automatically triggers Strict Mode if a function signature changes.


✨ Key Features

  • Polyglot AST Parsing: Accurate dependency detection for JavaScript, TypeScript, Python, and HTML.

  • Stateful Gatekeeper: The server tracks verification status. The commit_safe_edit tool returns ⛔ ACCESS DENIED if the Integrity Score is not 1.0.

  • Interactive Conflict Resolution: If the AI detects breaking changes, the server forces it to stop and ask the user for confirmation using a secure handshake protocol.

  • Smart Filtering: Automatically ignores standard language methods (e.g., .map(), print()) to keep the focus on your business logic.

🚀 The "#editmath" Protocol

The server enforces a strict workflow:

  1. 🔍 SCAN: The AI scans the target function using AST.

  2. 🎫 TICKET: The AI verifies dependencies. If conflicts exist, the server puts the request in PENDING state and demands user confirmation.

  3. 💾 COMMIT: Only with a valid ticket (or user override) can the AI save changes.

📦 Installation

  1. Clone the repository:

    git clone https://github.com/yrannkv/mcp-edit-math.git
    cd mcp-edit-math
  2. Install dependencies: Note: Specific versions are required for stability.

    pip install mcp tree-sitter==0.21.3 tree-sitter-javascript==0.21.0 tree-sitter-typescript==0.21.0 tree-sitter-html==0.20.3
  3. Configure your MCP Client: Add this to your configuration file (e.g., claude_desktop_config.json):

    {
      "mcpServers": {
        "edit-math": {
          "command": "python",
          "args": ["/absolute/path/to/mcp-edit-math/mcp_edit_math.py"]
        }
      }
    }

⚡ Quick Start (via uvx)

If you use uv, you can run the server directly without cloning the repo:

{
  "mcpServers": {
    "edit-math": {
      "command": "uvx",
      "args": ["mcp-edit-math"]
    }
  }
}

🤖 System Prompt (Required)

Add this to your AI's Custom Instructions or .cursorrules to activate the protocol:


=== 🛡️ EDIT MATH PROTOCOL (v1.5.0) ===
Trigger: When user types "#editmath".

You are operating under a strict safety protocol. Direct file editing is FORBIDDEN.
Follow this sequence precisely:

1. 🔍 SCAN: Call `scan_dependencies(code, target_function)`.
   - **REQUIRED:** Provide `file_path` (absolute or relative) to scope the security check.
   - Determine `language` ("js", "ts", "html", "python") based on file extension.

2. 🎫 GET TICKET: Call `calculate_integrity_score`.
   - **REQUIRED:** Provide `file_path` matching the scan step.
   - **REQUIRED:** Provide `proposed_header` to check for renaming.
   - **If server returns "STOP. INTERVENTION REQUIRED":**
     a. STOP generating immediately.
     b. Present the plan/conflicts to the user.
     c. ASK: "Do you approve? (Type 'ok')"
     d. **CRITICAL:** END YOUR TURN. Do not simulate user response.
     e. When user replies "ok", call `calculate_integrity_score` again with `confirmation_token='ok'`.

3. 💾 COMMIT: Call `commit_safe_edit`.
   - If you need to force a commit (e.g., for unverified external libs), ask the user first, then use `force_override=True`.

☕ Support the Project

If this tool saved you time or prevented a bug, you can support the development via crypto:

  • EVM (Ethereum / Base / BNB): 0x2D7CDf70F44169989953e4cfA671D0E456fBe465

  • Solana: CGG9JouoxAs5Lja948h8ktn3CxLmbVmH1ocxPLEPCfVx

  • Bitcoin: bc1q30u6rsyu8gx3urcf20p36npgj4uc2aan7k5ntn


License: Apache-2.0 Author: Annenkov Yuriy

Available Tools

3 tools
calculate_integrity_scoreC

Рассчитывает Integrity Score. Использует State Machine для защиты от "читерства" ИИ.

ParametersJSON Schema
NameRequiredDescriptionDefault
target_functionYes
dependenciesYes
verified_dependenciesYes
proposed_headerNo
breaking_change_descriptionNo
confirmation_tokenNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions using a State Machine for protection against AI 'cheating', which hints at some validation mechanism, but doesn't describe what the tool actually does behaviorally - whether it's a read-only analysis, a scoring algorithm, or something that modifies state. It doesn't disclose permissions needed, rate limits, side effects, or what the State Machine entails.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is brief (two sentences) and doesn't waste words, but it's also severely under-specified. While technically concise, the brevity comes at the cost of meaningful information. The structure is simple but doesn't effectively communicate the tool's purpose or usage.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity implied by 6 parameters (3 required) and the presence of an output schema, the description is inadequate. While the output schema may document return values, the description doesn't explain what the tool does, when to use it, what the parameters mean, or the behavioral context. For a tool with this many parameters and specialized purpose, the description leaves too many gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage for all 6 parameters, the description provides absolutely no information about what any parameter means. It doesn't mention target_function, dependencies, verified_dependencies, or any other parameters. The description fails completely to compensate for the lack of schema documentation, leaving all parameters semantically undefined.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states 'Рассчитывает Integrity Score' which translates to 'Calculates Integrity Score' - this is essentially a tautology that restates the tool name. While it mentions using a State Machine for AI 'cheating' protection, it doesn't explain what an Integrity Score actually measures or what resource it operates on. The purpose remains vague and doesn't distinguish from sibling tools like commit_safe_edit or scan_dependencies.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus the sibling tools (commit_safe_edit, scan_dependencies). It mentions protection against AI 'cheating' but doesn't specify the context or prerequisites for invoking this calculation. There's no explicit when-to-use or when-not-to-use guidance, leaving the agent with minimal usage direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

commit_safe_editD
ParametersJSON Schema
NameRequiredDescriptionDefault
target_functionYes
file_pathYes
full_file_contentYes
force_overrideNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

D1/5.0
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

scan_dependenciesC

Scans code for dependencies. Supports JS, TS, HTML, Python.

ParametersJSON Schema
NameRequiredDescriptionDefault
codeYes
target_functionYes
languageNoauto
ignore_customNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does (scanning for dependencies) but lacks details on behavioral traits such as whether it's read-only or destructive, performance characteristics, error handling, or output format. This is a significant gap for a tool with multiple parameters and an output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just one sentence, front-loaded with the core purpose. Every word earns its place, making it easy to parse quickly without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (4 parameters, 2 required) and the presence of an output schema, the description is minimally adequate but incomplete. It covers the basic purpose and language support, but lacks usage guidelines, parameter explanations, and behavioral context, leaving gaps that the agent must infer from other sources.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It only mentions supported languages, which relates to the 'language' parameter, but doesn't explain the semantics of 'code', 'target_function', or 'ignore_custom'. This leaves key parameters unclear, failing to add sufficient meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Scans code for dependencies' with a specific verb ('scans') and resource ('dependencies'), and it lists supported languages (JS, TS, HTML, Python). However, it doesn't explicitly differentiate from sibling tools like 'calculate_integrity_score' or 'commit_safe_edit', which might involve related code analysis but have distinct purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions supported languages, but doesn't specify scenarios, prerequisites, or exclusions, leaving the agent to infer usage from the tool name and parameters alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 3 tool updatesv1.0.0
    • First observedcalculate_integrity_score
    • First observedcommit_safe_edit
    • First observedscan_dependencies

TDQS

C2/5.0
Disambiguation3/5

The tools have distinct primary purposes (scoring, editing, scanning), but the descriptions are incomplete and vague, particularly for commit_safe_edit which lacks any description, making it unclear how it differs from the others. The overlap is minimal but clarity is hindered by poor documentation.

Naming Consistency4/5

All three tools follow a consistent verb_noun naming pattern (calculate_integrity_score, commit_safe_edit, scan_dependencies), which is predictable and readable. There are no deviations in style or convention across the tool names.

Tool Count2/5

With only 3 tools, the set feels thin for a server named 'mcp-edit-math', which suggests a broader scope involving editing and mathematical operations. The tools do not adequately cover this domain, lacking basic operations like create, update, or delete for edits or math calculations.

Completeness2/5

The tool surface is severely incomplete for the implied domain of editing and mathematics. There are significant gaps: no tools for performing mathematical calculations, editing content, or managing edits beyond the vague commit_safe_edit. The set does not support a coherent workflow, leading to potential agent failures.

Maintenance

ActivityInactive
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables AI agents to query architecture context, data contracts, and blast radius to prevent cross-repo architectural breakage before merging.
    24
    Apache 2.0
  • A
    license
    A
    quality
    B
    maintenance
    Enables AI coding assistants to analyze codebases locally before generating code, reducing duplication and enforcing architecture boundaries.
    1
    4
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    Fast pre-commit dependency gate for AI-assisted code changes. Answers "is this safe to commit?" with a PASS/WARN/BLOCK verdict in seconds, so you can catch risky blast radius before a bad commit, not after it. No database, no heavy setup.
    5
    113
    1
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Combines AST intelligence and guarded file operations to provide a secure, controlled repository workflow for coding agents, enabling structural code analysis and safe edits without unbounded editor access.
    690
    MIT

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yrannkv/mcp-edit-math'

If you have feedback or need assistance with the MCP directory API, please join our Discord server