| name | lsp-safe-edit |
| description | Wrap any code edit with before/after diagnostic comparison. Speculatively previews the change first (preview_edit), then applies to disk only if the error delta is acceptable. If post-edit errors appear, surfaces code actions for quick fixes. Handles single and multi-file edits. |
| user-invocable | true |
| allowed-tools | mcp__lsp__start_lsp mcp__lsp__open_document mcp__lsp__get_diagnostics mcp__lsp__preview_edit mcp__lsp__simulate_chain mcp__lsp__suggest_fixes mcp__lsp__format_document mcp__lsp__apply_edit Edit Write Bash |
| license | MIT |
| compatibility | Requires the agent-lsp MCP server (github.com/blackwell-systems/agent-lsp) |
| metadata | {"optional-capabilities":"codeActionProvider documentFormattingProvider","tool_permissions":{"phases":{"setup":"[Truncated]","speculative_preview":"[Truncated]","apply":"[Truncated]","verify_and_fix":"[Truncated]"},"global_forbidden":["mcp__lsp__rename_symbol","mcp__lsp__blast_radius"]}} |
Requires the agent-lsp MCP server.
lsp-safe-edit
Wrap any code edit with a before/after diagnostic comparison. Speculatively
previews the change in-memory before touching disk, then diffs errors introduced
vs. resolved after applying. If errors appear, surfaces code actions to fix them.
Prerequisites
LSP must be running for the target workspace. If not yet initialized, call
mcp__lsp__start_lsp with the workspace root before proceeding.
Auto-init note: agent-lsp supports workspace auto-inference from file paths.
Explicit start_lsp is only needed when switching workspace roots.
Input
- target file(s): One or more files to be edited (absolute paths).
- description of change: What you intend to edit and why.
Workflow
Step 1 — Open target file(s)
Call mcp__lsp__open_document for each file that will be edited:
mcp__lsp__open_document(file_path: "/abs/path/to/file.go", language_id: "go")
Step 2 — Capture baseline diagnostics (BEFORE)
Call mcp__lsp__get_diagnostics for each target file. Store as BEFORE.
For multi-file edits, collect diagnostics for all files involved.
BEFORE = mcp__lsp__get_diagnostics(file_path: "/abs/path/to/file.go")
If the server returns an empty list immediately after open, wait briefly and
retry — LSP analysis is async.
Step 3 — Speculative preview (preview_edit)
Before touching disk, call mcp__lsp__preview_edit to preview the
error delta of the intended change:
mcp__lsp__preview_edit(
file_path: "/abs/path/to/file.go",
start_line: <N>,
start_column: <col>,
end_line: <N>,
end_column: <col>,
new_text: "<replacement text>"
)
Returns net_delta (new errors introduced minus errors resolved) without
writing to disk.
Decision:
net_delta | Action |
|---|
| ≤ 0 | Proceed — edit improves or does not worsen error state |
| > 0 | Pause. Report introduced errors to user and ask: "Proceed anyway? [y/n]" |
If net_delta > 0 and user says "n", stop. Do not apply the edit.
Multi-file edits: covers one file at a time. For
edits spanning multiple files, run it for each file independently and sum the
deltas. If any file shows , pause before continuing.