首页
学习
活动
专区
圈层
工具
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
首页
学习
活动
专区
圈层
工具
MCP广场
MCP广场 >详情页
mcp-server-text-editor2025-06-130分享
github
开源的 Claude 内置文本编辑器工具版本实现:text_editor_20241022(Claude 3.5 版本)text_editor_20250124(Claude 3.7 版本)
By bhouston
2025-06-130
github
详情内容

Claude 文本编辑器 MCP 服务器

npm 版本
CI 状态
测试覆盖率

模型上下文协议标志

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

功能

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

支持的 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 桌面中配置

{
  "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. 叉取仓库
  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
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档