MCP Text Editor Server
MCP Text Editor 是一个面向行的API服务器,用于高效编辑文本文件,并针对LLM工具进行了优化,具有冲突检测和部分文件访问等功能。
简介
MCP 文本编辑服务器是一个基于行的文本文件编辑工具,通过标准化 API 提供高效的文件操作。它特别优化了 LLM 工具的部分文件访问,以最小化令牌使用。
Claude.app 用户安装
将以下配置添加到您的 Claude 桌面配置中:
# 编辑配置文件
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"text-editor": {
"command": "uvx",
"args": [
"mcp-text-editor"
]
}
}
}
安装选项
方法 1: 通过 uvx 运行
uvx mcp-text-editor
方法 2: 通过 Smithery 安装
npx -y @smithery/cli install mcp-text-editor --client claude
方法 3: 手动安装
# 1. 安装 Python 3.13+
pyenv install 3.13.0
pyenv local 3.13.0
# 2. 安装 uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# 3. 创建虚拟环境并安装依赖
uv venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
uv pip install -e ".[dev]"
# 4. 启动服务器
python -m mcp_text_editor
主要功能
- 面向行的文本文件编辑和读取
- 通过行范围指定的部分文件访问,最小化令牌使用
- 多文件操作支持
- 基于哈希的并发编辑冲突检测
- 多种编码支持 (utf-8, shift_jis, latin1 等)
使用方法
读取文件内容
单文件单范围:
{
"file_path": "path/to/file.txt",
"line_start": 1,
"line_end": 10,
"encoding": "utf-8"
}
多文件多范围:
{
"files": [
{
"file_path": "file1.txt",
"ranges": [
{"start": 1, "end": 10},
{"start": 20, "end": 30}
],
"encoding": "utf-8"
},
{
"file_path": "file2.txt",
"ranges": [
{"start": 5, "end": 15}
]
}
]
}
编辑文件内容
{
"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": "新内容第 5-8 行\n"
}
]
}
]
}
重要提示:
- 编辑前先使用
get_text_file_contents
获取当前哈希值 - 从下到上应用补丁以正确处理行号偏移
- 同一文件的补丁不应重叠
- 行号从 1 开始计算
end: null
表示文件末尾