Text Editor MCP server

Perform efficient line-oriented operations on text files.
Back to servers
Setup instructions
Provider
tumf
Release date
Dec 11, 2024
Language
Python
Package
Stats
7.7K downloads
146 stars

The MCP Text Editor Server is a powerful tool for line-oriented text file editing through a standardized API. It's optimized for LLM tools with efficient partial file access to minimize token usage and implements the Model Context Protocol for reliable file operations.

Installation

Option 1: Run via uvx

The quickest way to start using the MCP Text Editor Server:

uvx mcp-text-editor

Option 2: Smithery Installation

For Claude Desktop users, install automatically via Smithery:

npx -y @smithery/cli install mcp-text-editor --client claude

Option 3: Manual Installation

  1. Install Python 3.13+:
pyenv install 3.13.0
pyenv local 3.13.0
  1. Install uv:
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Create and set up the environment:
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install -e ".[dev]"

Option 4: Docker Installation

docker build --network=host -t mcp/text-editor .

Configuration for Claude.app

Add the following configuration to your Claude.app settings:

code ~/Library/Application\ Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "text-editor": {
      "command": "uvx",
      "args": [
        "mcp-text-editor"
      ]
    }
  }
}

Or with Docker:

{
  "mcpServers": {
    "text-editor": {
      "command": "docker",
      "args": [
          "run",
          "-i",
          "--rm",
          "--mount",
          "type=bind,src=/some/path/src,dst=/some/path/dst",
          "mcp/text-editor"
      ]
    }
  }
}

Usage

Starting the Server

Start the server directly:

python -m mcp_text_editor

Start with Docker:

docker run -i --rm --mount "type=bind,src=/some/path/src,dst=/some/path/dst" mcp/text-editor

With inspector:

npx @modelcontextprotocol/inspector docker run -i --rm --mount "type=bind,src=/some/path/src,dst=/some/path/dst" mcp/text-editor

MCP Tools

Getting File Contents

The get_text_file_contents tool retrieves file contents with line range specification.

Single Range Request:

{
  "file_path": "path/to/file.txt",
  "line_start": 1,
  "line_end": 10,
  "encoding": "utf-8"
}

Multiple Ranges Request:

{
  "files": [
    {
      "file_path": "file1.txt",
      "ranges": [
        {"start": 1, "end": 10},
        {"start": 20, "end": 30}
      ],
      "encoding": "shift_jis"
    },
    {
      "file_path": "file2.txt",
      "ranges": [
        {"start": 5, "end": 15}
      ]
    }
  ]
}

Parameters:

  • file_path: Path to the text file
  • line_start/start: Line number to start from (1-based)
  • line_end/end: Line number to end at (inclusive, null for end of file)
  • encoding: File encoding (default: "utf-8")

Patching File Contents

The patch_text_file_contents tool applies patches to text files with conflict detection.

Request Format:

{
  "files": [
    {
      "file_path": "file1.txt",
      "hash": "sha256-hash-from-get-contents",
      "encoding": "utf-8",
      "patches": [
        {
          "start": 5,
          "end": 8,
          "range_hash": "sha256-hash-of-content-being-replaced",
          "contents": "New content for lines 5-8\n"
        },
        {
          "start": 15,
          "end": null,
          "range_hash": "sha256-hash-of-content-being-replaced",
          "contents": "Content to append\n"
        }
      ]
    }
  ]
}

Important notes:

  • Always get the current hash using get_text_file_contents before editing
  • Patches are applied from bottom to top to handle line number shifts
  • Patches must not overlap within the same file
  • Line numbers are 1-based
  • end: null can be used to append content to the end of file

Common Usage Pattern

  1. Get current content and hash:
contents = await get_text_file_contents({
    "files": [
        {
            "file_path": "file.txt",
            "ranges": [{"start": 1, "end": null}]  # Read entire file
        }
    ]
})
  1. Edit file content:
result = await edit_text_file_contents({
    "files": [
        {
            "path": "file.txt",
            "hash": contents["file.txt"][0]["hash"],
            "encoding": "utf-8",
            "patches": [
                {
                    "line_start": 5,
                    "line_end": 8,
                    "contents": "New content\n"
                }
            ]
        }
    ]
})
  1. Handle conflicts:
if result["file.txt"]["result"] == "error":
    if "hash mismatch" in result["file.txt"]["reason"]:
        # File was modified by another process
        # Get new content and retry
        pass

Troubleshooting

Common Issues

  1. Permission Denied

    • Check file and directory permissions
    • Ensure the server process has necessary read/write access
  2. 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
  3. Encoding Issues

    • Verify file encoding matches the specified encoding
    • Use utf-8 for new files
    • Check for BOM markers in files
  4. Connection Issues

    • Verify the server is running and accessible
    • Check network configuration and firewall settings
  5. Performance Issues

    • Consider using smaller line ranges for large files
    • Monitor system resources (memory, disk space)
    • Use appropriate encoding for file type

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "text-editor" '{"command":"uvx","args":["mcp-text-editor"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "text-editor": {
            "command": "uvx",
            "args": [
                "mcp-text-editor"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "text-editor": {
            "command": "uvx",
            "args": [
                "mcp-text-editor"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later