这是一个开源实现,将 Claude 内置的文本编辑器工具作为 模型上下文协议 (MCP) 服务器。此包提供了与 Claude 内置的文本编辑器工具相同的功能,允许您通过标准化的 API 查看、编辑和创建文本文件。
此包实现了与 内置的 Claude 文本编辑器工具等效的工具版本:
text_editor_20241022 (Claude 3.5 Sonnet)text_editor_20250124 (Claude 3.7 Sonnet)但使用工具名称 'text_editor' 以避免与内置的 Claude 工具发生命名冲突。
# 从 npm 安装
npm install mcp-server-text-editor
# 或者使用 pnpm
pnpm add mcp-server-text-editor
# 使用 npx
npx -y mcp-server-text-editor
# 或者如果全局安装了
mcp-server-text-editor
{
"mcpServers": {
"textEditor": {
"command": "npx",
"args": ["-y", "mcp-server-text-editor"]
}
}
}
查看文件或目录的内容。
{
"command": "view",
"path": "/path/to/file.js",
"view_range": [1, 10] // 可选:仅显示第 1 到第 10 行
}
创建一个具有指定内容的新文件。
{
"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": "// 这一行由 Claude 插入"
}
撤销对文件所做的最后一次编辑。
{
"command": "undo_edit",
"path": "/path/to/file.js"
}
# 克隆仓库
git clone https://github.com/bhouston/mcp-server-text-editor.git
cd mcp-server-text-editor
# 安装依赖
pnpm install
# 构建项目
pnpm build
pnpm build: 构建 TypeScript 项目pnpm lint: 运行 ESLint 并自动修复pnpm format: 使用 Prettier 格式化代码pnpm clean: 删除构建产物pnpm clean:all: 删除构建产物和 node_modulespnpm test: 运行测试pnpm test:coverage: 带覆盖率报告运行测试此项目使用 Vitest 进行测试。
要运行测试:
# 运行所有测试
pnpm test
# 带覆盖率报告运行测试
pnpm test:coverage
测试覆盖率报告将在 coverage 目录中生成。
MIT
欢迎贡献!请随意提交拉取请求。
git checkout -b feature/amazing-feature)git commit -m '添加一些惊人的功能')git push origin feature/amazing-feature)