kinagaki/mcp-line-edit
If you are the rightful owner of mcp-line-edit and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
MCP server for precise line-based code editing operations.
mcp-line-edit
MCP server for precise line-based code editing operations.
Motivation
AI assistants are powerful for refactoring code, but they regenerate code rather than moving it. This means your carefully formatted comments, whitespace, and even subtle logic can change unexpectedly. For legacy codebases or team projects where clean diffs matter, this is a real problem.
This tool takes a different approach: mechanical copy-paste operations. Code is moved byte-for-byte, never regenerated. The AI decides what to move and where, while this tool handles the precise execution. All modification operations support dry-run mode to preview changes before applying them.
The result: exact code preservation, minimal diffs, and safe refactoring workflows.
Features
- Exact code manipulation: No LLM regeneration, preserves comments, whitespace, and formatting
- Line-based operations: Read, insert, replace, delete by line numbers
- Buffer support: Cut, copy, paste operations with a single buffer
- Dry-run mode: Preview changes before applying them
- Newline preservation: Maintains original line endings (CRLF/LF)
- UTF-8 encoding: Proper handling with error reporting
Installation
pip install git+https://github.com/kinagaki/mcp-line-edit.git
For development:
git clone https://github.com/kinagaki/mcp-line-edit.git
cd mcp-line-edit
pip install -e .
Usage
VS Code Configuration
Create .vscode/mcp.json in your workspace:
{
"servers": {
"line-edit": {
"command": "/path/to/venv/bin/mcp-line-edit"
}
}
}
For WSL users:
{
"servers": {
"line-edit": {
"command": "wsl",
"args": ["--", "mcp-line-edit"]
}
}
}
After adding the configuration, reload VS Code (Ctrl+Shift+P → Developer: Reload Window).
Available Tools
Basic Operations:
read_lines- Read specified line rangeinsert_lines- Insert content at specified positionreplace_lines- Replace line range with new contentdelete_lines- Delete specified line range
Buffer Operations:
cut_lines- Cut lines to buffer and delete from filecopy_lines- Copy lines to bufferpaste_buffer- Paste buffer content at specified positionshow_buffer- Show current buffer content
Convenience:
move_lines- Move lines between files (cut + paste)
All modification operations (insert_lines, replace_lines, delete_lines, move_lines) support optional dry_run parameter to preview changes without modifying files.
Example Usage
"Read lines 100-150 from src/main.f90"
→ Uses read_lines
"Move lines 10-34 from heat_LIB.f90 to the end of the file, but preview first"
→ Uses move_lines with dry_run=True
"That looks good, now do it for real"
→ Uses move_lines with dry_run=False
"Copy lines 50-75 to the buffer"
→ Uses copy_lines
"Paste the buffer at line 100 in utils.f90"
→ Uses paste_buffer
Use Cases
Code refactoring, module reorganization, extracting common definitions, separating test code—any task where you need to move code between files while preserving exact formatting and comments.
Requirements
- Python 3.10 or higher
- fastmcp
License
MIT License - see LICENSE file for details
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.