mcp-text-editor
This server provides line-oriented text file editing and reading capabilities over MCP, optimized for LLM tools with token-efficient partial access and hash-based concurrency control.
Read text file contents from multiple files and line ranges in one call, with file and range hashes for conflict detection
Create new text files with specified content (file must not already exist)
Append content to existing files with file-hash validation
Insert content before or after a specific line with hash validation
Delete specific line ranges from a file with hash validation
Patch/replace line ranges using both file hash and range hash to prevent concurrent-edit conflicts
Supports multiple files and multiple ranges per operation
Supports various encodings (utf-8, shift_jis, latin1, etc.)
Handles line-number shifts correctly when applying patches
Provides error handling for hash mismatches, invalid ranges, encoding issues, and permission errors
Integration for code coverage reporting, as indicated by the codecov badge in the README.
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., "@mcp-text-editor show lines 15-30 from config.yaml"
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.
MCP Text Editor Server
A Model Context Protocol (MCP) server that provides line-oriented text file editing capabilities through a standardized API. Optimized for LLM tools with efficient partial file access to minimize token usage.
Quick Start for Claude.app Users
To use this editor with Claude.app, add the following configuration to your prompt:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json{
"mcpServers": {
"text-editor": {
"command": "uvx",
"args": [
"mcp-text-editor"
]
}
}
}Related MCP server: RBT Document Editor
Overview
MCP Text Editor Server is designed to facilitate safe and efficient line-based text file operations in a client-server architecture. It implements the Model Context Protocol, ensuring reliable file editing with robust conflict detection and resolution. The line-oriented approach makes it ideal for applications requiring synchronized file access, such as collaborative editing tools, automated text processing systems, or any scenario where multiple processes need to modify text files safely. The partial file access capability is particularly valuable for LLM-based tools, as it helps reduce token consumption by loading only the necessary portions of files.
Key Benefits
Line-based editing operations
Token-efficient partial file access with line-range specifications
Optimized for LLM tool integration
Safe concurrent editing with hash-based validation
Atomic multi-file operations
Robust error handling with custom error types
Comprehensive encoding support (utf-8, shift_jis, latin1, etc.)
Features
Line-oriented text file editing and reading
Smart partial file access to minimize token usage in LLM applications
Get text file contents with line range specification
Read multiple ranges from multiple files in a single operation
Line-based patch application with correct handling of line number shifts
Edit text file contents with conflict detection
Flexible character encoding support (utf-8, shift_jis, latin1, etc.)
Support for multiple file operations
Proper handling of concurrent edits with hash-based validation
Memory-efficient processing of large files
Requirements
Python 3.11 or higher
POSIX-compliant operating system (Linux, macOS, etc.) or Windows
Sufficient disk space for text file operations
File system permissions for read/write operations
Install Python 3.11+
pyenv install 3.11.6
pyenv local 3.11.6Install uv (recommended) or pip
curl -LsSf https://astral.sh/uv/install.sh | shCreate virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e ".[dev]"Requirements
Python 3.13+
POSIX-compliant operating system (Linux, macOS, etc.) or Windows
File system permissions for read/write operations
Installation
Run via uvx
uvx mcp-text-editorInstalling via Smithery
To install Text Editor Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install mcp-text-editor --client claudeManual Installation
Install Python 3.13+
pyenv install 3.13.0
pyenv local 3.13.0Install uv (recommended) or pip
curl -LsSf https://astral.sh/uv/install.sh | shCreate virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e ".[dev]"Usage
Start the server:
python -m mcp_text_editorMCP Tools
The server provides several tools for text file manipulation:
get_text_file_contents
Get the contents of one or more text files with line range specification.
Request:
The tool accepts a files array. Each file contains one or more line ranges using
start and end. File paths must be absolute.
{
"files": [
{
"file_path": "/absolute/path/to/file.txt",
"ranges": [
{"start": 1, "end": 10},
{"start": 20, "end": null}
]
}
],
"encoding": "utf-8"
}Parameters:
file_path: Absolute path to the text filestart: First line to read (1-based)end: Last line to read (inclusive);nullreads through end of fileencoding: File encoding for all requested files (default:utf-8)
Response:
The top-level object is keyed by absolute file path. file_hash protects the
whole-file state; each range_hash protects the corresponding range.
{
"/absolute/path/to/file.txt": {
"file_hash": "sha256-hash-of-the-file",
"ranges": [
{
"content": "Lines 1-10 content",
"start": 1,
"end": 10,
"range_hash": "sha256-hash-of-this-range",
"total_lines": 50,
"content_size": 512
}
]
}
}patch_text_file_contents
Apply one or more non-overlapping patches to one file. Read the target ranges
first and pass both the current file_hash and each matching range_hash.
Request:
{
"file_path": "/absolute/path/to/file.txt",
"file_hash": "sha256-hash-from-get-response",
"patches": [
{
"start": 5,
"end": 8,
"range_hash": "sha256-hash-of-lines-5-through-8",
"contents": "New content for lines 5-8\n"
}
],
"encoding": "utf-8"
}Important notes:
Obtain current hashes with
get_text_file_contentsimmediately before editing.Use
startandend;line_startandline_endare not accepted.Patches are applied from bottom to top and must not overlap.
Line numbers are 1-based.
Use
append_text_file_contents,insert_text_file_contents, ordelete_text_file_contentsfor those specialized operations.Use the same encoding for the read and patch calls.
Success response:
{
"result": "ok",
"file_hash": "sha256-hash-of-new-file-contents",
"reason": null,
"suggestion": null,
"hint": null
}Error response:
{
"result": "error",
"reason": "Content range hash mismatch",
"suggestion": "get",
"hint": "Please run get_text_file_contents first to get current content and hashes"
}Common Usage Pattern
Call
get_text_file_contentsfor the exact range to replace.Read
file_hashand the range'srange_hashfrom the keyed response.Call
patch_text_file_contentswith those hashes and the same range.If the result is an error, read the file again before retrying.
path = "/absolute/path/to/file.txt"
contents = await get_text_file_contents({
"files": [{
"file_path": path,
"ranges": [{"start": 5, "end": 8}]
}]
})
file_info = contents[path]
selected_range = file_info["ranges"][0]
result = await patch_text_file_contents({
"file_path": path,
"file_hash": file_info["file_hash"],
"patches": [{
"start": 5,
"end": 8,
"range_hash": selected_range["range_hash"],
"contents": "New content\n"
}]
})Error Handling
The server handles various error cases:
File not found
Permission errors
Hash mismatches (concurrent edit detection)
Invalid patch ranges
Overlapping patches
Encoding errors (when file cannot be decoded with specified encoding)
Line number out of bounds
Security Considerations
File Path Validation: The server validates all file paths to prevent directory traversal attacks
Access Control: Proper file system permissions should be set to restrict access to authorized directories
Hash Validation: All file modifications are validated using SHA-256 hashes to prevent race conditions
Input Sanitization: All user inputs are properly sanitized and validated
Error Handling: Sensitive information is not exposed in error messages
Troubleshooting
Common Issues
Permission Denied
Check file and directory permissions
Ensure the server process has necessary read/write access
Hash Mismatch and Range Hash Errors
The file was modified by another process
Content being replaced has changed
Run get_text_file_contents to get fresh hashes
Encoding Issues
Verify file encoding matches the specified encoding
Use utf-8 for new files
Check for BOM markers in files
Connection Issues
Verify the server is running and accessible
Check network configuration and firewall settings
Performance Issues
Consider using smaller line ranges for large files
Monitor system resources (memory, disk space)
Use appropriate encoding for file type
Development
Setup
Clone the repository
Create and activate a Python virtual environment
Install development dependencies:
uv pip install -e ".[dev]"Run tests:
make all
Code Quality Tools
Ruff for linting
Black for code formatting
isort for import sorting
mypy for type checking
pytest-cov for test coverage
Testing
Tests are located in the tests directory and can be run with pytest:
# Run all tests
pytest
# Run tests with coverage report
pytest --cov=mcp_text_editor --cov-report=term-missing
# Run specific test file
pytest tests/test_text_editor.py -vCurrent test coverage: 90%
Project Structure
mcp-text-editor/
├── mcp_text_editor/
│ ├── __init__.py
│ ├── __main__.py # Entry point
│ ├── models.py # Data models
│ ├── server.py # MCP Server implementation
│ ├── service.py # Core service logic
│ └── text_editor.py # Text editor functionality
├── tests/ # Test files
└── pyproject.toml # Project configurationLicense
MIT
Contributing
Fork the repository
Create a feature branch
Make your changes
Run tests and code quality checks
Submit a pull request
Type Hints
This project uses Python type hints throughout the codebase. Please ensure any contributions maintain this.
Error Handling
All error cases should be handled appropriately and return meaningful error messages. The server should never crash due to invalid input or file operations.
Testing
New features should include appropriate tests. Try to maintain or improve the current test coverage.
Code Style
All code should be formatted with Black and pass Ruff linting. Import sorting should be handled by isort.
Available Tools
6 toolsappend_text_file_contentsB
Append content to an existing text file. The file must exist.
Inputs: contents (required), file_hash (required), file_path (required), encoding.
create_text_fileA
Create a new text file with given content. The file must not exist already.
Inputs: contents (required), file_path (required), encoding.
delete_text_file_contentsA
Delete specified content ranges from a text file. The file must exist. File paths must be absolute. You need to provide the file_hash comes from get_text_file_contents.
Inputs: ranges (required), file_hash (required), file_path (required), encoding.
get_text_file_contentsA
Read text file contents from multiple files and line ranges. Returns file contents with hashes for concurrency control and line numbers for reference. The hashes are used to detect conflicts when editing the files. File paths must be absolute.
Inputs: files (required), encoding.
insert_text_file_contentsA
Insert content before or after a specific line in a text file. Uses hash-based validation for concurrency control. You need to provide the file_hash comes from get_text_file_contents.
Inputs: contents (required), file_hash (required), file_path (required), after, +2 more.
patch_text_file_contentsA
Apply patches to text files with hash-based validation for concurrency control.you need to use get_text_file_contents tool to get the file hash and range hash every time before using this tool. you can use append_text_file_contents tool to append text contents to the file without range hash, start and end. you can use insert_text_file_contents tool to insert text contents to the file without range hash, start and end.
Inputs: patches (required), file_hash (required), file_path (required), encoding.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool targets a distinct operation: create, read, append, insert, delete range, and patch. However, patch_text_file_contents can be seen as overlapping with insert and delete since patches may subsume those operations, so agents might occasionally hesitate between them.
Most tools follow a verb_text_file_contents pattern, which is clear and consistent. The exception is create_text_file, which drops the _contents suffix and breaks the otherwise uniform convention.
Six tools is a well-scoped set for a text file editor. Each tool covers a necessary primitive operation without redundant or bloated additions.
The server provides create, read, append, insert, delete-range, and patch operations, covering the core editing lifecycle. A whole-file overwrite or file deletion operation is missing, but most workflows can be accomplished with the existing tools.
Maintenance
Related MCP Connectors
A real-time, multiplayer filesystem for agents and humans: shared files, live edits, history.
Work on your own computers from Claude or ChatGPT: run commands, edit and search files.
Use your Mac, Windows or Linux computer from ChatGPT, Claude or Codex: files, commands, documents.
Read and write your Fresh Jots notes from Claude, Cursor, and any MCP client.
Related MCP Servers
- AlicenseBqualityDmaintenanceAn open source implementation of the Claude built-in text editor tool versions: text\_editor\_20241022 (Claude 3.5 Sonnet) text\_editor\_20250124 (Claude 3.7 Sonnet)166 npm36MIT
- AlicenseAqualityDmaintenanceEnables efficient editing of RBT documents with structured operations that read and modify specific sections or blocks. Reduces LLM token consumption by 80-95% compared to full file operations through smart caching and partial document access.8MIT
- AlicenseNot gradedqualityDmaintenanceProvides hashline-based file editing using line-addressed edits and content hashes for integrity verification. It enables LLMs to perform precise file modifications while ensuring edits are rejected if the file content has changed since the last read.22 npm9MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server that provides line-oriented text file editing capabilities through a standardized API. Optimized for LLM tools with efficient partial file access to minimize token usage.MIT