
MCP File Editor Server
Enables comprehensive file operations including reading, writing, searching, and editing files with advanced features like regex-based replacements, line-specific modifications, and directory-wide search capabilities. Provides 8 robust tools for safe file manipulation with content verification and detailed error handling.
README
MCP File Editor Server
A comprehensive Model Context Protocol (MCP) server that provides advanced file operations for reading, writing, searching, and editing files. This server offers 9 powerful tools for file manipulation with robust error handling and comprehensive test coverage.
Features
Core Tools
-
read_file
- Read file contents with flexible options- Full file reading or specific line ranges
- Optional line number prefixes
- Support for partial file reading
-
replace_in_file
- Regex-based string replacement- Single or multiple occurrence replacement
- Complex regex pattern support
- Safe replacement with occurrence limits
-
delete_from_file
- Remove content between line numbers- Line content verification for safety
- Single or multi-line deletion
- Precise line range targeting
-
insert_into_file
- Insert content at specific positions- Before/after line placement
- End-of-file appending
- Line content verification
-
replace_lines_in_file
- Replace content between lines- Multi-line content replacement
- Line content verification
- Flexible content insertion
-
multireplace_lines_in_file
- Multiple line replacements with automatic adjustment- Perform multiple edits in a single operation
- Automatic line number adjustment after each edit
- Detailed success/failure reporting for each edit
- Handles complex line shifting scenarios
-
search_file
- Search within individual files- Regex pattern matching
- Context lines (before/after)
- Detailed match reporting
-
list_files
- Directory content listing- File and directory enumeration
- File size information
- Recursive directory support
-
search_directory
- Search across multiple files- Directory-wide regex search
- Include/exclude pattern filtering
- Recursive subdirectory searching
Key Features
- Robust Error Handling: User-friendly error messages with actionable guidance
- Path Validation: Absolute path enforcement with helpful error messages
- Content Verification: Line content verification to prevent accidental edits
- Comprehensive Testing: 80 test cases covering all functionality
- TypeScript Implementation: Full type safety and modern JavaScript features
- FastMCP Framework: Built on the FastMCP library for optimal performance
Installation
Prerequisites
- Node.js 16.x or later
- npm or yarn package manager
Install Dependencies
npm install
Build the Project
npm run build
Usage
Cursor-compatible MCP server config
"mcpServers": {
"file-edit": {
"command": "npx",
"args": ["mcp-file-editor@latest"]
}
}
Starting the Server
node build/index.js
The server will start and listen for MCP client connections via stdio transport.
MCP Client Integration
This server is designed to work with MCP-compatible clients. The server communicates via stdio and supports the following MCP tools:
Example Tool Usage
// Read a file
const result = await client.callTool({
name: 'read_file',
arguments: {
file_path: '/absolute/path/to/file.txt',
show_line_numbers: true,
start_line: 1,
end_line: 10
}
});
// Search for patterns
const searchResult = await client.callTool({
name: 'search_directory',
arguments: {
directory_path: '/path/to/search',
regexp: 'TODO|FIXME',
recursive: true
}
});
// Multiple line replacements with automatic adjustment
const multiEditResult = await client.callTool({
name: 'multireplace_lines_in_file',
arguments: {
file_path: '/path/to/file.txt',
edits: [
{
line_start: 10,
line_end: 15,
line_start_contents: 'Line 10: Tenth line',
contents: 'REPLACED LINES 10-15\nWith new content'
},
{
line_start: 25,
line_end: 30,
line_start_contents: 'Line 25: Twenty-fifth line',
contents: 'REPLACED LINES 25-30\nWith different content'
}
]
}
});
Testing
Run the comprehensive test suite:
npm test
The test suite includes:
- 73 total tests across 4 test files
- Unit tests for all 8 tools
- Error handling validation
- Edge case coverage
- Integration testing with MCP client
Test Coverage
read-file.test.ts
- 16 tests for file reading operationsediting-tools.test.ts
- 26 tests for file modification tools (including multireplace_lines_in_file)search-tools.test.ts
- 22 tests for search and directory operationsutils.test.ts
- 16 tests for utility functions
API Reference
Tool Parameters
read_file
file_path
(string, required): Absolute path to the fileshow_line_numbers
(boolean, optional): Prefix lines with numbersstart_line
(number, optional): Starting line number (1-based)end_line
(number, optional): Ending line number (1-based)full
(boolean, optional): Read entire file (mutually exclusive with line ranges)
replace_in_file
file_path
(string, required): Absolute path to the fileregex_source
(string, required): Regular expression patterntarget
(string, required): Replacement stringmultiple
(boolean, optional): Allow multiple replacements
delete_from_file
file_path
(string, required): Absolute path to the fileline_start
(number, required): Starting line numberline_end
(number, required): Ending line numberline_start_contents
(string, required): Expected content of starting line
insert_into_file
file_path
(string, required): Absolute path to the fileline_number
(number, required): Target line number (0 for end)line_contents
(string, required): Expected content of target linewhere
(enum, required): 'before' or 'after'contents
(string, required): Content to insert
replace_lines_in_file
file_path
(string, required): Absolute path to the fileline_start
(number, required): Starting line numberline_end
(number, required): Ending line numberline_start_contents
(string, required): Expected content of starting linecontents
(string, required): Replacement content
multireplace_lines_in_file
file_path
(string, required): Absolute path to the fileedits
(array, required): Array of edit operationsline_start
(number, required): Starting line number (1-based)line_end
(number, required): Ending line number (1-based)line_start_contents
(string, required): Expected content of starting linecontents
(string, required): New content to replace the lines with
search_file
file_path
(string, required): Absolute path to the fileregexp
(string, required): Regular expression patternlines_before
(number, optional): Context lines before matcheslines_after
(number, optional): Context lines after matches
list_files
directory_path
(string, required): Absolute path to the directory
search_directory
directory_path
(string, required): Absolute path to the directoryregexp
(string, required): Regular expression patternrecursive
(boolean, optional): Search subdirectorieslines_before
(number, optional): Context lines before matcheslines_after
(number, optional): Context lines after matchesinclude
(string, optional): File pattern to includeexclude
(string, optional): File/directory pattern to exclude
Error Handling
The server provides detailed error messages for common issues:
- Path validation: Clear messages for relative paths and non-existent files
- Content verification: Helpful guidance when line content doesn't match
- File operations: Descriptive errors for read/write failures
- Parameter validation: Specific guidance for invalid parameters
Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
This project is licensed under the MIT License. See LICENSE file for details.
Architecture
The server is built with:
- TypeScript for type safety and modern JavaScript features
- FastMCP framework for MCP protocol implementation
- Zod for schema validation
- Vitest for comprehensive testing
- fs-extra for enhanced file system operations
The architecture follows clean separation of concerns with:
- Main server implementation in
src/index.ts
- Utility functions in
src/utils.ts
- Comprehensive test suite with proper MCP client integration
- Modular tool implementations with consistent error handling
推荐服务器

Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。