Text Editor

by danielpodrazka

3 stars
Not rated
GitHub

About

Provides a secure Python-based text editing interface with two-step verification and syntax validation for collaborative code file manipulation

Details

Author
danielpodrazka
Repository
danielpodrazka/editor-mcp
GitHub stars
3
License
MIT License
Categories
File Management, Productivity, Developer Tools, Design, AI, Search, Infrastructure, Frontend, Communication

- File Selection: Set a file to work with using absolute paths
- Read Operations:
- Read entire files with line numbers using skim
- Read specific line ranges with prefixed line numbers using read
- Find specific text within files using find_line
- Find and extract function definitions in Python and JavaScript/JSX files using find_function
- Edit Operations:
- Two-step editing process with diff preview
- Select and overwrite text with ID verification
- Clean editing workflow with select → overwrite → confirm/cancel pattern
- Syntax checking for Python (.py) and JavaScript/React (.js, .jsx) files
- Create new files with content
- File Management:
- Create new files with proper initialization
- Delete files from the filesystem
- List directory contents with listdir
- Testing Support:
- Run Python tests with run_tests
- Set Python paths for proper module resolution
- Safety Features:
- Content ID verification to prevent conflicts
- Line count limits to prevent resource exhaustion
- Syntax checking to maintain code integrity
- Protected paths to restrict access to sensitive files

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Text Editor
    Command (node, npx, python, etc.) editor-mcp
    Environment
    • PROTECTED_PATHS *.env,.env*,config*.json,*secret*,/etc/passwd,/home/user/.ssh/id_rsa
    • MAX_SELECT_LINES 100
    • ENABLE_JS_SYNTAX_CHECK 0
    • FAIL_ON_JS_SYNTAX_ERROR 0
    • FAIL_ON_PYTHON_SYNTAX_ERROR 1

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

This MCP was developed and tested with Claude Desktop. You can download Claude Desktop on any platform.
For Claude Desktop on Linux, you can use an unofficial installation script (uses the official file), recommended repository:

set_file

Sets the current file to work with. Parameters: filepath (str): Absolute path to the file.

skim

Reads full text from the current file. Each line is prefixed with its line number.

read

Reads text from the current file from start line to end line. Parameters: start (int): Start line number (1-based indexing), end (int): End line number (1-based indexing).

select

Select a range of lines from the current file for subsequent overwrite operation. Parameters: start (int): Start line number (1-based), end (int): End line number (1-based).

overwrite

Prepare to overwrite a range of lines in the current file with new text. Parameters: new_lines (list): List of new lines to overwrite the selected range.

confirm

Apply pending changes from the overwrite operation.

cancel

Discard pending changes from the overwrite operation.

delete_file

Delete the currently set file.

new_file

Creates a new file and automatically sets it as the current file for subsequent operations. Parameters: filepath (str): Path of the new file.

find_line

Find lines that match provided text in the current file. Parameters: search_text (str): Text to search for in the file.

find_function

Find a function or method definition in the current Python or JavaScript/JSX file. Parameters: function_name (str): Name of the function or method to find.

listdir

Lists the contents of a directory. Parameters: dirpath (str): Path to the directory to list.

run_tests

Run Python tests with pytest.

set_python_path

Set Python paths for proper module resolution.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "text editor": {
            "env": {
                "PROTECTED_PATHS": "*.env,.env*,config*.json,*secret*,/etc/passwd,/home/user/.ssh/id_rsa",
                "MAX_SELECT_LINES": "100",
                "ENABLE_JS_SYNTAX_CHECK": "0",
                "FAIL_ON_JS_SYNTAX_ERROR": "0",
                "FAIL_ON_PYTHON_SYNTAX_ERROR": "1"
            },
            "args": [],
            "command": "editor-mcp"
        }
    }
}

Linux

{
    "env": {
        "PROTECTED_PATHS": "*.env,.env*,config*.json,*secret*,/etc/passwd,/home/user/.ssh/id_rsa",
        "MAX_SELECT_LINES": "100",
        "ENABLE_JS_SYNTAX_CHECK": "0",
        "FAIL_ON_JS_SYNTAX_ERROR": "0",
        "FAIL_ON_PYTHON_SYNTAX_ERROR": "1"
    },
    "args": [],
    "command": "editor-mcp"
}

Macos

{
    "env": {
        "PROTECTED_PATHS": "*.env,.env*,config*.json,*secret*,/etc/passwd,/home/user/.ssh/id_rsa",
        "MAX_SELECT_LINES": "100",
        "ENABLE_JS_SYNTAX_CHECK": "0",
        "FAIL_ON_JS_SYNTAX_ERROR": "0",
        "FAIL_ON_PYTHON_SYNTAX_ERROR": "1"
    },
    "args": [],
    "command": "editor-mcp"
}

Windows

{
    "env": {
        "PROTECTED_PATHS": "*.env,.env*,config*.json,*secret*,/etc/passwd,/home/user/.ssh/id_rsa",
        "MAX_SELECT_LINES": "100",
        "ENABLE_JS_SYNTAX_CHECK": "0",
        "FAIL_ON_JS_SYNTAX_ERROR": "0",
        "FAIL_ON_PYTHON_SYNTAX_ERROR": "1"
    },
    "args": [],
    "command": "editor-mcp"
}

A Python-based text editor server built with FastMCP that provides powerful tools for file operations. This server enables reading, editing, and managing text files through a standardized API with a unique multi-step approach that significantly improves code editing accuracy and reliability for LLMs and AI assistants.

- File Selection: Set a file to work with using absolute paths
- Read Operations:

- Read entire files with line numbers usingskim
- Read specific line ranges with prefixed line numbers usingread
- Find specific text within files usingfind_line
- Find and extract function definitions in Python and JavaScript/JSX files usingfind_function

- Two-step editing process with diff preview
- Select and overwrite text with ID verification
- Clean editing workflow with select → overwrite → confirm/cancel pattern
- Syntax checking for Python (.py) and JavaScript/React (.js, .jsx) files
- Create new files with content

- Create new files with proper initialization
- Delete files from the filesystem
- List directory contents withlistdir

- Run Python tests withrun_tests
- Set Python paths for proper module resolution

- Content ID verification to prevent conflicts
- Line count limits to prevent resource exhaustion
- Syntax checking to maintain code integrity
- Protected paths to restrict access to sensitive files

The editor-mcp includes powerful capabilities that come with certain security considerations:

- Jailbreak Risk: The editor-mcp can potentially be jailbroken when reading a file that has harmful instructions embedded inside. Malicious content in files being edited could contain instructions that manipulate the AI assistant.
- Arbitrary Code Execution: If running tests is enabled, there is a risk of arbitrary code execution through manipulated test files or malicious Python code.
- Data Exposure: Access to file system operations could potentially expose sensitive information if proper path protections aren't configured.
- Use thePROTECTED_PATHSenvironment variable to restrict access to sensitive files and directories.
- Disable test running capabilities in production environments unless absolutely necessary.
- Carefully review files before opening them, especially if they come from untrusted sources.
- Consider running the editor in a sandboxed environment with limited permissions.

This text editor's unique design solves critical problems that typically affect LLM code editing:

-

Prevents Loss of Context- Traditional approaches often lead to LLMs losing overview of the codebase after a few edits. This implementation maintains context through the multi-step process.

Avoids Resource-Intensive Rewrites- LLMs typically default to replacing entire files when confused, which is costly, slow, and inefficient. This editor enforces selective edits.

Provides Visual Feedback- The diff preview system allows the LLM to actually see and verify changes before committing them, dramatically reducing errors.

Enforces Syntax Checking- Automatic validation for Python and JavaScript/React ensures that broken code isn't committed.

Improves Edit Reasoning- The multi-step approach gives the LLM time to reason between steps, reducing haphazard token production.

The editor implements several safeguards to ensure system stability and prevent resource exhaustion:

- Maximum Edit Lines: By default, the editor enforces a 50-line limit for any single edit operation

This MCP was developed and tested with Claude Desktop. You can download Claude Desktop on any platform. For Claude Desktop on Linux, you can use an unofficial installation script (uses the official file), recommended repository:https://github.com/emsi/claude-desktop/tree/main

Once you have Claude Desktop installed, follow the instructions below to install this specific MCP:

Easy Installation with UVX (Recommended)

The easiest way to install the Editor MCP is using the provided installation script:

# Clone the repository git clone https://github.com/danielpodrazka/editor-mcp.git cd editor-mcp # Run the installation script chmod +x install.sh ./install.sh

- Check if UVX is installed and install it if necessary
- Install the Editor MCP in development mode
- Make theeditor-mcpcommand available in your PATH

# Install directly from GitHub uvx install git+https://github.com/danielpodrazka/mcp-text-editor.git # Or install from a local clone git clone https://github.com/danielpodrazka/mcp-text-editor.git cd mcp-text-editor uvx install -e .
pip install git+https://github.com/danielpodrazka/mcp-text-editor.git # Or from a local clone git clone https://github.com/danielpodrazka/mcp-text-editor.git cd mcp-text-editor pip install -e .
uv pip compile requirements.in -o uv.lock

After installation, you can start the Editor MCP server using one of these methods:

# Using the installed script editor-mcp # Or using the Python module python -m text_editor.server

You can add the Editor MCP to your MCP configuration file:

{ "mcpServers": { "text-editor": { "command": "editor-mcp", "env": { "MAX_SELECT_LINES": "100", "ENABLE_JS_SYNTAX_CHECK": "0", "FAIL_ON_PYTHON_SYNTAX_ERROR": "1", "FAIL_ON_JS_SYNTAX_ERROR": "0", "PROTECTED_PATHS": ".env,.env,config.json,secret,/etc/passwd,/home/user/.ssh/id_rsa" } } } }

The Editor MCP supports several environment variables to customize its behavior:

-

MAX_SELECT_LINES: "100" - Maximum number of lines that can be edited in a single operation (default is 50)

ENABLE_JS_SYNTAX_CHECK: "0" - Enable/disable JavaScript and JSX syntax checking (default is "1" - enabled)

FAIL_ON_PYTHON_SYNTAX_ERROR: "1" - When enabled, Python syntax errors will automatically cancel the overwrite operation (default is enabled)

FAIL_ON_JS_SYNTAX_ERROR: "0" - When enabled, JavaScript/JSX syntax errors will automatically cancel the overwrite operation (default is disabled)

PROTECTED_PATHS: Comma-separated list of file patterns or paths that cannot be accessed, supporting wildcards (e.g., ".env,.env,/etc/passwd")

Sample MCP Config When Building From Source

{ "mcpServers": { "text-editor": { "command": "/home/daniel/pp/venvs/editor-mcp/bin/python", "args": ["/home/daniel/pp/editor-mcp/src/text_editor/server.py"], "env": { "MAX_SELECT_LINES": "100", "ENABLE_JS_SYNTAX_CHECK": "0", "FAIL_ON_PYTHON_SYNTAX_ERROR": "1", "FAIL_ON_JS_SYNTAX_ERROR": "0", "PROTECTED_PATHS": ".env,.env,config.json,secret,/etc/passwd,/home/user/.ssh/id_rsa" } } } }

The Editor MCP provides 13 powerful tools for file manipulation, editing, and testing:

- filepath(str): Absolute path to the file

Reads full text from the current file. Each line is prefixed with its line number.

- Dictionary containing lines with their line numbers, total number of lines, and the max edit lines setting

{ "lines": [ [1, "def hello():"], [2, " print(\"Hello, world!\")"], [3, ""], [4, "hello()"] ], "total_lines": 4, "max_select_lines": 50 }

Reads text from the current file from start line to end line.

- start(int): Start line number (1-based indexing)
- end(int): End line number (1-based indexing)

- Dictionary containing lines with their line numbers as keys, along with start and end line information

{ "lines": [ [1, "def hello():"], [2, " print(\"Hello, world!\")"], [3, ""], [4, "hello()"] ], "start_line": 1, "end_line": 4 }

Select a range of lines from the current file for subsequent overwrite operation.

- start(int): Start line number (1-based)
- end(int): End line number (1-based)

- Dictionary containing the selected lines, line range, and ID for verification

- This tool validates the selection against max_select_lines
- The selection details are stored for use in the overwrite tool
- This must be used before calling the overwrite tool

Prepare to overwrite a range of lines in the current file with new text.

- new_lines(list): List of new lines to overwrite the selected range

- Diff preview showing the proposed changes

- This is the first step in a two-step process:
- First call overwrite() to generate a diff preview
- Then call confirm() to apply or cancel() to discard the pending changes

Apply pending changes from the overwrite operation.

- Operation result with status and message

- This is one of the two possible actions in the second step of the editing process
- The selection is removed upon successful application of changes

Discard pending changes from the overwrite operation.

- Operation result with status and message

- This is one of the two possible actions in the second step of the editing process
- The selection remains intact when changes are cancelled

- Operation result with status and message

Creates a new file and automatically sets it as the current file for subsequent operations.

- Operation result with status, message, and selection info
- The first line is automatically selected for editing

- Automatically creates parent directories if they don't exist
- Sets the newly created file as the current working file
- The first line is pre-selected, ready for immediate editing

- Files matching certain patterns (like*.env) can be created normally
- However, once you move to another file, these protected files cannot be reopened
- This allows for a "write-once, protect-after" workflow for sensitive configuration files
- Example: You can createconfig.env, populate it with example config, but cannot reopen it later

- This tool will fail if the current file exists and is not empty

Find lines that match provided text in the current file.

- search_text(str): Text to search for in the file

- Dictionary containing matching lines with their line numbers and total matches

{ "status": "success", "matches": [ [2, " print(\"Hello, world!\")"] ], "total_matches": 1 }

- Returns an error if no file path is set
- Searches for exact text matches within each line
- The id can be used for subsequent edit operations

Find a function or method definition in the current Python or JavaScript/JSX file.

- function_name(str): Name of the function or method to find

- Dictionary containing the function lines with their line numbers, start_line, and end_line

{ "status": "success", "lines": [ [10, "def hello():"], [11, " print(\"Hello, world!\")"], [12, " return True"] ], "start_line": 10, "end_line": 12 }

- For Python files, this tool uses Python's AST and tokenize modules to accurately identify function boundaries including decorators and docstrings
- For JavaScript/JSX files, this tool uses a combination of approaches:

- Primary method: Babel AST parsing when available (requires Node.js and Babel packages)
- Fallback method: Regex pattern matching for function declarations when Babel is unavailable

- dirpath(str): Path to the directory to list

- Dictionary containing list of filenames and the path queried

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.