mcpField
C
Claude Text Editor MCP Server

Claude Text Editor MCP Server

本地服务
npmjs.comAI 与智能体3684 周前更新

关于 Claude Text Editor MCP Server

Claude Text Editor MCP Server 是 Claude 内置文本编辑工具的开源实现,以 MCP 服务形式提供。它面向需要通过标准接口查看、创建和编辑文本文件的开发者与 Agent 使用者,接口与 Claude 内置工具保持一致。

主要功能

  1. 01查看文件内容,可指定行范围
  2. 02创建新文件
  3. 03替换文件中的文本
  4. 04在指定行号插入文本
  5. 05撤销上一次编辑

适用场景

  1. 01让 Claude 通过 MCP 客户端读取并修改本地源代码文件
  2. 02在 Claude Desktop 中为文件编辑提供统一接口

MCP 相关

该项目是 MCP 服务,向 MCP 客户端暴露名为 text_editor 的工具,支持 view、create、str_replace、insert 和 undo_edit 命令。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"text-editor": {
"command": "npx",
"args": [
"-y",
"mcp-server-text-editor"
]
}
}
}
启动命令npx -y mcp-server-text-editor

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npmmcp-server-text-editor

工具

1

收录的工具列表 · 更新于 3 周前

参数类型必填说明
commandenum是要运行的命令。允许的选项:`view`、`create`、`str_replace`、`insert`、`undo_edit`。view | create | str_replace | insert | undo_edit
pathstring是文件或目录的绝对路径,例如 `/repo/file.py` 或 `/repo`。
file_textstring否`create` 命令的必需参数,指定要创建的文件内容。
insert_linenumber否`insert` 命令的必需参数。`new_str` 将插入到 `path` 中 `insert_line` 指定行之后。
new_strstring否`str_replace` 命令的可选参数,包含要替换的新字符串(如果未提供,则不会添加字符串)。`insert` 命令的必需参数,包含要插入的字符串。
old_strstring否`str_replace` 命令的必需参数,包含 `path` 中要替换的字符串。
view_rangearray否当 `path` 指向文件时,`view` 命令的可选参数。如果未提供,则显示整个文件。如果提供,则显示指定行号范围内的文件,例如 `[11, 12]` 将显示第 11 和第 12 行。行号从 1 开始。设置为 `[start_line, -1]` 可显示从 `start_line` 到文件末尾的所有行。
descriptionstring是使用文本编辑器的原因(最多 80 个字符)

详细介绍

Claude 文本编辑器 MCP 服务

npm version CI Status Test Coverage

Model Context Protocol Logo

这是一个开源实现,将 Claude 内置文本编辑器工具作为 Model Context Protocol(MCP)服务提供。该软件包提供与 Claude 内置文本编辑器工具相同的功能,让你能够通过标准化 API 查看、编辑和创建文本文件。

功能

  • 与 Claude 文本编辑器的 API 完全一致:实现与 Claude 内置文本编辑器工具完全相同的接口
  • MCP 服务实现:遵循 Model Context Protocol 标准,以集成 AI 工具
  • 文件操作:
    • 查看文件内容,可选择指定行范围
    • 创建新文件
    • 替换现有文件中的文本
    • 在指定行号插入文本
    • 撤销之前的编辑

支持的 Claude 文本编辑器版本

此软件包实现了与以下版本的内置 Claude 文本编辑器工具等效的工具:

  • text_editor_20241022(Claude 3.5 Sonnet)
  • text_editor_20250124(Claude 3.7 Sonnet)

但使用工具名称“text_editor”,以避免与 Claude 内置工具名称冲突。

安装

# Install from npm
npm install mcp-server-text-editor

# Or with pnpm
pnpm add mcp-server-text-editor

使用方法

启动服务
# Using npx
npx -y mcp-server-text-editor

# Or if installed globally
mcp-server-text-editor
在 Claude Desktop 中配置
{
  "mcpServers": {
    "textEditor": {
      "command": "npx",
      "args": ["-y", "mcp-server-text-editor"]
    }
  }
}
工具命令
查看

查看文件或目录的内容。

{
  "command": "view",
  "path": "/path/to/file.js",
  "view_range": [1, 10] // Optional: Show lines 1-10 only
}
创建

使用指定内容创建新文件。

{
  "command": "create",
  "path": "/path/to/file.js",
  "file_text": "console.log('Hello, world!');"
}
字符串替换

替换文件中的文本。

{
  "command": "str_replace",
  "path": "/path/to/file.js",
  "old_str": "console.log('Hello, world!');",
  "new_str": "console.log('Hello, Claude!');"
}
插入

在指定行插入文本。

{
  "command": "insert",
  "path": "/path/to/file.js",
  "insert_line": 5,
  "new_str": "// This line was inserted by Claude"
}
撤销编辑

撤销对文件所做的上一次编辑。

{
  "command": "undo_edit",
  "path": "/path/to/file.js"
}

开发

前置条件
  • Node.js 18+
  • pnpm
设置
# Clone the repository
git clone https://github.com/bhouston/mcp-server-text-editor.git
cd mcp-server-text-editor

# Install dependencies
pnpm install

# Build the project
pnpm build
脚本
  • pnpm build:构建 TypeScript 项目
  • pnpm lint:运行 ESLint 并自动修复
  • pnpm format:使用 Prettier 格式化代码
  • pnpm clean:移除构建产物
  • pnpm clean:all:移除构建产物和 node_modules
  • pnpm test:运行测试
  • pnpm test:coverage:运行测试并生成覆盖率报告
测试

此项目使用 Vitest 进行测试。

运行测试:

# Run all tests
pnpm test

# Run tests with coverage report
pnpm test:coverage

测试覆盖率报告将生成在 coverage 目录中。

许可证

MIT

贡献

欢迎贡献!请随时提交 Pull Request。

  1. Fork 此仓库
  2. 创建功能分支(git checkout -b feature/amazing-feature)
  3. 提交更改(git commit -m 'Add some amazing feature')
  4. 推送到分支(git push origin feature/amazing-feature)
  5. 创建 Pull Request

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。