Plan Lock MCP
This server manages a markdown plan file as external memory, letting an agent work through tasks one locked, atomic step at a time.
Create a plan (
plan_create): write a list of steps toplan.md(project root) or.opencode/plan.md, backing up any existing plan and updating ignore rules; returns the absolute path.Activate the next step (
plan_next): mark the next pending step[~]and return its id, plan path and text — refused if a lock is already active, and returnsPLAN_DONEwhen nothing is pending.Complete a step (
plan_done): mark the active step[x]and attach a short note.Fail a step (
plan_fail): mark the active step[!]and attach a failure reason.Enforce sequencing: the server, not the prompt, guarantees at most one active step at a time, rejecting out-of-order or duplicate activation.
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., "@Plan Lock MCP Create a plan to add user login, then start the first step"
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.
Plan Lock MCP
Plan Lock MCP makes an LLM work through a markdown plan one atomic step at a time, holding a lock on the active step until it is resolved.
🎯 The problem
Local coding models — especially the 30B class such as Qwen3-Coder — tend to emit eight to ten tool and shell calls in a single turn when asked to change code. Every call returns its output into the same conversation. The context window fills with interleaved command output, it becomes hard to tell which result belongs to which command, and a failed step is buried next to unrelated successful ones.
On the following turn the model has to re-derive "where was I" from that noisy history. On local hardware this is expensive: the KV cache is extended with tokens that describe bookkeeping rather than progress.
The result is slower and more chaotic work. Parallelism is often presented as a speedup, but for a local LLM it usually does the opposite: more output to parse, more state to reconcile, and a higher chance that one failing call invalidates the others.
Naming the failure mode
The technical term for emitting several tool calls in one turn is parallel tool calling. The failure described above is narrower: the calls have no dependency order. We call it uncoordinated fan-out — also described as tool call flooding or over-eager tool use. When the same turn edits several files it becomes fan-out editing or scattergun editing: shots go everywhere without sequencing. The conversation then ends up in context thrashing (state thrashing), where results interleave and state keeps changing without settling. Parallelism is not the problem; the missing coordination is. Plan Lock replaces that fan-out with one explicit transition at a time.
In short: the tool layer, not the prompt, decides which step may run now. Everything else waits.
Related MCP server: agent-project-mcp
📖 Overview
Source | Reference |
📄 Active plan |
|
🧩 MCP surface |
|
🔒 Lock rule | at most one |
🗃️ Ignore rules | root |
⚡ In one line: create a plan, activate one step, resolve it, repeat. The markdown file is the source of truth and the server enforces the transition. Nothing else is written.
💡 The idea
One atomic, verifiable step at a time. A step has a clear boundary: it is started, then either completed with a note or failed with a reason.
The plan lives outside the model. It is a markdown file, not a conversation history. The model re-reads it when it needs state instead of carrying the whole task history in context.
The lock is enforced by the server, not by the prompt. While a step is
[~],plan_nextrefuses to activate another one. Discipline is a property of the tool layer.Transitions are idempotent and crash-safe:
[ ]→[~]→[x]/[!]. State is on disk, so after a crash or restart the model continues from the marked step rather than guessing.
✨ Features
🔒 Enforced lock — one
[~]step at a time, checked by the server on every call.📄 External memory — the plan is a markdown file, not conversation state.
🛡️ Crash-safe writes — temp file, fsync and
os.replaceunder a serialized lock.📁 Project-aware location — root
plan.mdwhen project markers exist, otherwise.opencode/plan.md.🧭 Absolute path in responses — the model never has to search for the active file.
🧪 70 tests, seven categories — Smoke, Sanity, Unit, Regression, Integration, E2E and UI, plus GitHub Actions CI.
🌐 English and Türkçe docs — both tours stay in sync.
🧠 How it works
1. The loop
plan_create(steps)writes a fresh plan and backs up any previous one.plan_next()activates the first pending step and returns its id, the absolute plan path and its text:Next step (id=1, file: /home/user/projects/api/plan.md): Create database schema.The model does only that step, then calls
plan_done(id, note)orplan_fail(id, reason).Repeat.
plan_next()returnsPLAN_DONEwhen no pending steps remain.
flowchart LR
A["plan_create"] --> B["plan_next"]
B --> C{"lock active?"}
C -->|yes| D["error: Plan Lock active"]
C -->|no| E["next [ ] becomes [~]"]
E --> F["do only that step"]
F --> G{"result?"}
G -->|success| H["plan_done: [x] + note"]
G -->|failure| I["plan_fail: [!] + error"]
H --> B
I --> B
B -->|no pending| J["PLAN_DONE"]2. Tool contract
Tool | Parameters | Behaviour |
|
| Writes the plan file (root |
| none | Activates the next |
|
| Marks the active |
|
| Marks the active |
A step cannot be started twice: the server checks the active lock before activating anything else. Completed and failed steps are terminal.
3. Step states
stateDiagram-v2
[*] --> Pending: plan_create
Pending --> Active: plan_next (only when no step is [~])
Active --> Completed: plan_done(id, note)
Active --> Failed: plan_fail(id, reason)
Active --> Active: plan_next → "Plan Lock active" (rejected)
Completed --> [*]
Failed --> [*]Only one step can be Active at a time. Completed and Failed are terminal: [x] carries a — note: suffix and [!] a — error: suffix. plan_create resets the cycle and backs up the previous file.
🗂️ What gets pulled from where
Source | What | Target |
🧑💻 Agent |
| new plan file, with a backup of the previous one |
📄 Active plan | first pending |
|
🖊️ Tool arguments |
|
|
📁 Working directory | project markers such as | root |
🗃️ Existing ignore files | entries already present | no duplicates added by |
The example plan in examples/plan.md shows the exact
format the server writes. No network or external model catalog is consulted.
🤖 Current free chat models
Plan Lock does not publish or filter a model catalog. The live free chat model
list lives in check-opencode-free-models,
which keeps ~/.config/opencode/opencode.jsonc in sync with the OpenCode
Console. Plan Lock consumes the MCP surface described above and never changes
model configuration.
📂 Plan file
Location rule
The plan sits next to the code when the working directory looks like a project root: it contains .git, pyproject.toml, package.json, Cargo.toml or go.mod. Any other directory, such as a scratch folder or a home directory, keeps the plan in .opencode/, where a loose markdown file is less intrusive.
Working directory | Plan file | Ignore rules |
Project root (marker present) |
|
|
Other directory |
|
|
Both paths are relative to the server's working directory and nothing is written to the home directory, so each project keeps its own independent plan. plan_create reports the absolute path it wrote:
Plan Lock created: 3 steps -> /home/user/projects/api/plan.mdThe model always knows which file is the source of truth without searching for it.
Format
# Plan — myproject
- created: 1732451234
- [ ] 1. Create database schema
- [~] 2. Implement API endpoints
- [x] 3. Configure authentication — note: JWT tokens configured
- [!] 4. Set up Redis cache — error: Connection timeoutThe header records the project name (basename of the working directory) and the creation time as a unix timestamp.
Marker | Meaning |
| Pending. |
| Active (locked). At most one step may have this marker. |
| Completed, with a |
| Failed, with a |
A real, fully completed plan from the macOS project media-studio is kept in examples/plan.md. It shows six resolved steps, each with a note; that project reported 441 tests passing and a clean build.
Backup and ignore handling
plan_create also keeps the plan out of version control. A root-level plan is added to the working directory's .gitignore, which is created when missing; existing lines are preserved and entries are never duplicated. The .opencode/ fallback gets its own .opencode/.gitignore with plan.md, plan.md.bak and .gitignore itself. Either way the plan and its backup never show up as untracked. When a new plan replaces an old one, the old content is written to the backup file next to it first.
🏗️ Architecture
Plan Lock MCP is a thin enforcement layer around one markdown file. The model carries no plan state in memory: every tool call re-reads the active plan file, validates the requested transition, and writes the whole file back atomically. The file is the source of truth; the server is the referee.
flowchart LR
classDef client fill:#e3f2fd,stroke:#1976d2,color:#0d47a1
classDef decision fill:#fff3e0,stroke:#ef6c00,color:#e65100
classDef action fill:#e8f5e9,stroke:#2e7d32,color:#1b5e20
classDef disk fill:#f3e5f5,stroke:#6a1b9a,color:#4a148c
Agent["🧑💻 Coding agent"]:::client
Agent -->|"one tool call at a time"| Guard{"Guard checks:<br/>lock free? id valid?<br/>status = [~]?"}:::decision
Guard -->|"no"| Reject["Error response<br/>plan unchanged"]:::decision
Guard -->|"yes"| Write["_single_line + atomic write<br/>(RLock held throughout)"]:::action
Write --> Plan[("active plan file<br/>cwd/plan.md or .opencode/plan.md")]:::disk
Plan -->|"re-read on every call"| Guard
Plan -->|"step id + text / confirmation"| Agent
Reject --> AgentHow to read it:
The agent only sends requests. It never edits the plan file itself; the server writes it.
The guard is the discipline. While a step is
[~],plan_nextis rejected;plan_done/plan_failrequire a matching active id.The plan is the memory. Each call starts by reading the file, so a crash or restart loses nothing.
Writes are atomic and serialized.
tempfile.mkstemp+os.replaceunderthreading.RLockprevent partial files and double activation.
🚀 Quick start
1. Requirements
Requirement | Notes |
Python | 3.10+, with the runtime dependency |
MCP client | OpenCode Desktop or another stdio MCP client |
Working directory | a project root or a scratch folder; |
2. Run
pip install . # provides the `planlock` console script
planlock --version # prints planlock 1.0.0
python3 /path/to/planlock.py # starts the stdio MCP serverRegister the server with the MCP client (for example opencode.json):
{
"mcp": {
"planlock": {
"type": "local",
"command": ["python3", "/path/to/planlock.py"],
"cwd": ".",
"enabled": true
}
}
}The cwd matters: it decides which project the server belongs to, and whether the plan sits at the project root or under .opencode/.
3. Flags
Flag or entry point | Effect |
(none) | Start the MCP server on stdio. |
| Print the version and exit without starting the server. |
| Write a fresh plan and report its absolute path. |
| Activate the next pending step or report |
| Resolve the active step. |
4. Example output
Plan Lock created: 3 steps -> /home/user/projects/api/plan.md
Next step (id=1, file: /home/user/projects/api/plan.md): Create database schema
Step 1 completed: schema written
Next step (id=2, file: /home/user/projects/api/plan.md): Implement API endpoints
PLAN_DONE5. Agent prompt
Add this directive to the agent's system prompt:
Plan Lock MCP is active. Call only one tool at a time.
Before starting a coding task, call plan_create.
Before each step, call plan_next and work only on the step it returns.
When the step finishes, call plan_done, or plan_fail if it failed.
Do not call other tools while a step is active.
If in doubt, read the plan file at the path plan_create reported.The prompt is a reminder, not the enforcement. The lock itself is in the server.
⏰ Desktop & crontab
Plan Lock is driven by the MCP client, not by a schedule. In OpenCode Desktop,
register the server with cwd pointed at the project; each tool call re-reads
the active plan, so no crontab entry is needed. A scheduled job may read the
reported plan path to report a step stuck as [~], but it must not edit the
plan. Resolving a step belongs to plan_done or plan_fail.
📂 Project structure
planlock-mcp/
├── planlock.py # MCP server: the four tools and the file lock
├── pyproject.toml # Package metadata, entry point, dependencies
├── py.typed # PEP 561 marker for type checkers
├── pytest.ini # Collects test_*.py and *-tests.py
├── .ruff.toml # Lint configuration
├── .pre-commit-config.yaml # Local hook configuration
├── requirements.txt # Runtime dependency (mcp)
├── requirements-dev.txt # Test and lint dependencies
├── README.md # English tour
├── README.tr.md # Turkish tour
├── CHANGELOG.md # Release history
├── CONTRIBUTING.md # Development conventions
├── SECURITY.md # Vulnerability reporting policy
├── LICENSE # MIT license
├── .github/workflows/ci.yml # Lint and test on push and pull request
├── docs/
│ ├── README.md # Documentation index
│ ├── guides/RELEASING.md # Version bump and publish procedure
│ └── testing/TESTING.md # Suite map and runner flags
├── examples/plan.md # A real completed plan in server format
└── test/
├── test.sh # Runner: Ruff + pytest
├── README.md # Test folder guide
└── py/ # Eight test files, 70 casesGenerated and local state (.venv/, caches, dist/, uv.lock, .wrongstack/) is gitignored and left out of the tree.
🧱 Design notes
threading.RLockwith a decorator serializes each read-check-write cycle inside one server process, so two simultaneous tool calls cannot both see an unlocked plan and activate the same step.Atomic writes use
tempfile.mkstempin the target directory plusos.replace. The temporary file and the directory are fsynced, so a crash or power loss cannot leave a half-written or vanished plan, and the rename stays on the same filesystem._single_linecollapses whitespace in step text, notes, and reasons. A newline in a tool argument cannot inject a forged- [~]line and bypass the lock.No in-memory plan state. Every call re-reads the file, which keeps restarts simple and makes the on-disk plan the single source of truth.
Clean stdio. Nothing is printed to
stdout; diagnostics do not corrupt the MCP transport.
🧪 Testing & CI
The suite has 70 deterministic tests, all offline. They are grouped into seven
categories, following the layered model used by check-opencode-free-models:
Category | Flag | Scope |
💨 Smoke |
| Compile, load, register tools, golden path, |
✅ Sanity |
| Exact messages, header format, plan locations. |
🔬 Unit |
| Tool behaviour in a fresh temporary directory. |
🩹 Regression |
| Injection, concurrency and durability fixes. |
🔗 Integration |
| Multi-call flows verified on disk. |
🎯 E2E |
| Real stdio JSON-RPC transport. |
🖥️ UI |
| User-facing MCP client surface (no GUI exists). |
./test/test.sh # Ruff + pytest
./test/test.sh --no-install # skip dependency installation
./test/test.sh --ui # one category, e.g. automated UIThe full suite map and flags live in docs/testing/TESTING.md.
CI runs Ruff and the full suite on every push to main and on pull requests.
⚠️ Limitations
The prompt does not make the model perfectly disciplined. It can still decide to skip the plan, work on a later step, or forget to release a lock. The MCP checks make this visible rather than silent: an out-of-order step is rejected instead of quietly corrupting the plan. Recovery is manual but cheap: read the plan file at the path plan_create returned, see the [~] step, and either finish it with plan_done or record the failure with plan_fail.
The lock is per server process. Two independent server processes pointed at the same working directory are not serialized against each other. There is also no validation of a plan file that was edited by hand into an invalid shape, such as more than one [~] step or ids that skip numbers; plan_create always writes a well-formed plan, but hand-edited files can confuse the parser. A duplicated id is tolerated: plan_done and plan_fail prefer the active line, so the lock can still be released.
📚 Documentation
Document | Purpose |
Index of the repository documentation. | |
Setup, test and commit conventions. | |
Release history. | |
Vulnerability reporting policy. | |
MIT license. |
🔮 Roadmap
✅ Done: four MCP tools, enforced lock, atomic fsync-backed writes, backup and ignore handling, seven test categories, CI, and English and Türkçe tours.
Remaining: cross-process locking for multiple server processes on one working directory, stricter validation of hand-edited plans, and optional read-only CLI inspection of the active plan.
📄 License
MIT. See LICENSE.
Available Tools
4 toolsplan_createA
Create a new plan and write it to the active plan file.
The plan file is plan.md in a project root and .opencode/plan.md
everywhere else; see _plan_paths for the rule.
Args: steps: List of step descriptions to add to the plan.
Returns: A message reporting the number of created steps and the absolute path of the plan file on success, or an error message on failure.
Inputs: steps (required). Returns: result
plan_doneB
Mark the active [~] step as completed [x] and append a note.
Args: id: ID of the completed step. note: Short completion note to append to the step.
Returns: A success or error message.
Inputs: id (required), note (required). Returns: result
plan_failB
Mark the active [~] step as failed [!] and append a reason.
Args: id: ID of the failed step. reason: Reason for the failure.
Returns: A success or error message.
Inputs: id (required), reason (required). Returns: result
plan_nextA
Activate the next pending plan step ([~]) and return it.
Returns: The ID, absolute plan path and text of the next step; an error message if a lock is already active or the plan file is missing; 'PLAN_DONE' when all steps are done.
Inputs: no named parameters. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool maps to a distinct lifecycle action: create plan, activate next step, complete active step, or fail active step. The active-step state model makes plan_done and plan_fail clearly distinguishable by outcome.
All tools use a consistent plan_ prefix with lowercase snake_case verbs. The pattern is predictable and readable across the set.
Four tools is well-scoped for a narrow plan-lock workflow, and each tool has a clear role in the lifecycle. There is no unnecessary surface area.
The core create-next-complete/fail cycle is covered, but the set lacks a status/inspection tool to view the current plan or active lock. It also has no reset, cancel, or reopen operation, which could create dead ends after failures or lost context.
Maintenance
Related MCP Connectors
The plan your AI agents work from. Project management and customer feedback for agent teams.
Versioned memory for agents: markdown docs with history, safe concurrent commits, human claim links.
Task coordination for AI agents. Exclusive locks, shared files, handoffs, per-agent spending limits.
Agent-native notes, tasks, dev-docs, vaults, sync & handoffs. MCP + OpenAPI dual surface.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnforces a git-tracked, code-checked finite state machine that hands control between a planning director and a local Ollama implementor, exposing tools to check phase status, transition states, and run the implementor to execute plan step files one at a time. It enables a project to be planned, implemented step by step with per-step test gating, and validated before completion.2MIT
- AlicenseNot gradedqualityCmaintenanceEnables any MCP-capable coding agent to share one plain-Markdown project state — goals, tasks, decision logs, and session handoffs — stored in a project's .apm/ directory, with lock-safe concurrent writes and consistency checks that flag stale, blocked, or unowned work. This lets multiple agents and a human CLI resume work across interrupted sessions without a database or external service.MIT
- AlicenseNot gradedqualityAmaintenanceEnables structured multi-agent workflows by managing task claims, action logs, handoffs, and health-gated completion while keeping specifications as filesystem Markdown artifacts.29 npmMIT
- AlicenseNot gradedqualityAmaintenanceEnables AI coding providers to run structured multi-agent workflows by claiming tasks, logging actions, managing handoffs, and enforcing server-side health gates across explorer, consultant, builder, and reviewer roles. Specifications stay as Markdown on disk while tracked task state, acceptance evidence, and completion checks are owned by the server.29 npmMIT