Write boundary
The guarded state machine behind structural and text-file changes.
A requested edit is not enough to authorize a write. ast-mcp requires a route that matches the target's capabilities and proves the caller is operating on current state.
Route selection
| Target or intent | Required route |
|---|---|
| Inspect supported methods | file_capabilities |
| Structural or semantic patch | file_patch with patchStrategy: "ast" when effective |
| Small exact text patch | file_patch with patchStrategy: "aider_block" when effective |
| New file | file_write |
| Rename | file_rename |
| Metadata-only change | file_chattr |
| Deletion | file_delete |
Parseable source commonly supports both patch strategies. The agent selects one explicitly; configuration can narrow the effective methods but never silently changes the selection.
Commit sequence
- Resolve and canonicalize every batch path.
- Preflight read, write, delete, symlink, and approval policy for the complete batch.
- Confirm the requested route matches each file's capabilities.
- Compare every supplied SHA-256 with current state.
- Build candidates from reviewed ordered operations and parse structural rewrites.
- Acquire cooperating locks in deterministic path order.
- Recheck policy, approval, configuration generation, and source hashes inside the lock.
- Format the candidate according to the resident configuration snapshot without touching live targets.
- Atomically replace files and release locks on success or failure.
A preview may return a short-lived, one-use receipt bound to the session, source hash, configuration generation, normalized operations, and unformatted strategy candidate. Preview does not run formatters or create formatter staging files. Receipt commit formats that candidate, then writes the formatted result after authorization and freshness checks. A stale hash or receipt, ambiguous Aider block, unexpected AST match count, capped preview, formatter rejection, or lost MCP connection is a safe stop.
Concurrency
In-process queues coordinate calls inside one server. Filesystem lock files coordinate cooperating processes. Sorting multi-file lock acquisition prevents lock-order inversions, and the hash recheck inside the lock closes the race between preview and commit.