fileditor-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +128 -0
- package/docs/MCP-INTERFACE.cn.md +976 -0
- package/docs/MCP-INTERFACE.en.md +881 -0
- package/docs/README.cn.md +128 -0
- package/package.json +27 -0
- package/src/handlers/applyDiff.js +298 -0
- package/src/handlers/insertContent.js +179 -0
- package/src/handlers/listFiles.js +65 -0
- package/src/handlers/readFile.js +109 -0
- package/src/handlers/searchAndReplace.js +198 -0
- package/src/handlers/setWorkspace.js +26 -0
- package/src/handlers/writeFile.js +98 -0
- package/src/index.js +20 -0
- package/src/server.js +85 -0
- package/src/tools/toolDefinitions.js +291 -0
- package/src/utils/fileUtils.js +238 -0
- package/test/ApplyDiffHandler.test.js +754 -0
- package/test/InsertContentHandler.test.js +371 -0
- package/test/ListFilesHandler.test.js +302 -0
- package/test/ReadFileHandler.test.js +213 -0
- package/test/SearchAndReplaceHandler.test.js +505 -0
- package/test/SetWorkspaceHandler.test.js +290 -0
- package/test/WriteFileHandler.test.js +289 -0
- package/test/runAllTests.js +233 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 bluetooth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# FileEditor MCP Server
|
|
2
|
+
|
|
3
|
+
[π English Interface Doc](docs/MCP-INTERFACE.en.md) | [π δΈζζ₯ε£ζζ‘£](docs/MCP-INTERFACE.cn.md) | [π δΈζREADME](docs/README.cn.md)
|
|
4
|
+
|
|
5
|
+
**AI-Optimized File Operations Server** - Built on Model Context Protocol, specifically engineered for AI coding assistants to perform sophisticated code editing, refactoring, and batch modification tasks with precision and efficiency.
|
|
6
|
+
|
|
7
|
+
## π― Design Philosophy
|
|
8
|
+
|
|
9
|
+
**Built for AI Programming** - This project is specifically designed for AI models' code editing requirements, providing precise block-level operations, intelligent matching algorithms, and batch processing capabilities that enable AI to safely and efficiently execute complex code modification tasks.
|
|
10
|
+
|
|
11
|
+
## π Core Features
|
|
12
|
+
|
|
13
|
+
### π File Operation Tools (7 Tools)
|
|
14
|
+
- **`set_workspace`** - Workspace isolation (must be called first)
|
|
15
|
+
- **`read_files`** - Smart file reading (batch, line ranges, with line numbers)
|
|
16
|
+
- **`write_files`** - Batch file writing (single/multiple files, create/overwrite)
|
|
17
|
+
- **`list_files`** - Directory traversal (recursive support)
|
|
18
|
+
- **`insert_contents`** - Precise content insertion (multiple files, negative line numbers, end insertion)
|
|
19
|
+
- **`apply_diffs`** - **Advanced diff application** (batch operations, atomic mode, intelligent whitespace handling)
|
|
20
|
+
- **`search_and_replace`** - Pattern replacement (regex, line ranges, case-insensitive)
|
|
21
|
+
|
|
22
|
+
### π Security Features
|
|
23
|
+
- **Workspace Isolation**: Strictly limit operation scope, prevent directory traversal attacks
|
|
24
|
+
- **Path Security**: Automatic validation and resolution of relative paths
|
|
25
|
+
- **Atomic Operations**: Batch modifications succeed completely or rollback entirely
|
|
26
|
+
|
|
27
|
+
### β‘ AI-Optimized Features
|
|
28
|
+
- **Batch Processing Engine**: Handle multiple file operations in a single API call
|
|
29
|
+
- **Intelligent Matching Algorithm**: `trim` mode handles code formatting differences with high tolerance
|
|
30
|
+
- **Detailed Operation Feedback**: Complete success/failure information for AI debugging and decision-making
|
|
31
|
+
- **Non-blocking Error Handling**: Partial failures don't prevent other operations from continuing
|
|
32
|
+
|
|
33
|
+
## π οΈ Quick Start
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Install dependencies
|
|
37
|
+
pnpm install
|
|
38
|
+
|
|
39
|
+
# Start server
|
|
40
|
+
pnpm start
|
|
41
|
+
|
|
42
|
+
# Development mode (auto-restart)
|
|
43
|
+
pnpm dev
|
|
44
|
+
|
|
45
|
+
# Run tests
|
|
46
|
+
pnpm test
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Requirements**: Node.js β₯18, pnpm
|
|
50
|
+
|
|
51
|
+
## π‘ Usage Examples
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
// Scenario 1: Workspace initialization (must be called first)
|
|
55
|
+
{
|
|
56
|
+
"name": "set_workspace",
|
|
57
|
+
"arguments": { "path": "/path/to/your/project" }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Scenario 2: Batch code file analysis
|
|
61
|
+
{
|
|
62
|
+
"name": "read_files",
|
|
63
|
+
"arguments": {
|
|
64
|
+
"path": ["src/main.js", "src/utils.js", "package.json"],
|
|
65
|
+
"line_range": "1-50" // Optional: read only first 50 lines
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Scenario 3: Intelligent code refactoring (tolerates whitespace differences)
|
|
70
|
+
{
|
|
71
|
+
"name": "apply_diffs",
|
|
72
|
+
"arguments": {
|
|
73
|
+
"path": "src/config.js",
|
|
74
|
+
"search_content": [
|
|
75
|
+
"const API_URL = 'localhost';",
|
|
76
|
+
"const PORT = 3000;"
|
|
77
|
+
],
|
|
78
|
+
"replace_content": [
|
|
79
|
+
"const API_URL = process.env.API_URL || 'localhost';",
|
|
80
|
+
"const PORT = process.env.PORT || 3000;"
|
|
81
|
+
],
|
|
82
|
+
"start_line": [5, 7],
|
|
83
|
+
"atomic": true, // Atomic mode: all succeed or all rollback
|
|
84
|
+
"trim": true // Smart mode: ignore whitespace differences
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## ποΈ Architecture Design
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
src/
|
|
93
|
+
βββ index.js # Application entry
|
|
94
|
+
βββ server.js # MCP server main class
|
|
95
|
+
βββ tools/
|
|
96
|
+
β βββ toolDefinitions.js # Tool definitions and schema
|
|
97
|
+
βββ handlers/ # Tool handlers
|
|
98
|
+
β βββ applyDiff.js # apply_diffs (batch + atomic support)
|
|
99
|
+
β βββ readFile.js # read_files
|
|
100
|
+
β βββ writeFile.js # write_files
|
|
101
|
+
β βββ listFiles.js # list_files
|
|
102
|
+
β βββ insertContent.js # insert_contents
|
|
103
|
+
β βββ searchAndReplace.js # search_and_replace
|
|
104
|
+
β βββ setWorkspace.js # set_workspace
|
|
105
|
+
βββ utils/
|
|
106
|
+
βββ fileUtils.js # Common file operation utilities
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Design Principles**: Modular architecture, single responsibility, easy to maintain and extend
|
|
110
|
+
|
|
111
|
+
## π Test Coverage
|
|
112
|
+
|
|
113
|
+
- β
**7 Complete Handler Test Suites**
|
|
114
|
+
- β
**Edge Cases and Error Handling Tests**
|
|
115
|
+
- β
**Batch Operations and Atomic Mode Validation**
|
|
116
|
+
- β
**Security and Path Validation Tests**
|
|
117
|
+
|
|
118
|
+
## π Why Choose FileEditor MCP
|
|
119
|
+
|
|
120
|
+
1. **AI-Native Design** - Specifically optimized for AI programming assistants' workflow
|
|
121
|
+
2. **High-Performance Batch Processing** - Reduce API calls, improve processing efficiency
|
|
122
|
+
3. **Intelligent Error Tolerance** - Handle real-world code formatting and whitespace differences
|
|
123
|
+
4. **Enterprise-Grade Security** - Strict workspace isolation and permission control
|
|
124
|
+
5. **Complete Test Coverage** - Reliability and stability guarantee
|
|
125
|
+
|
|
126
|
+
## π License
|
|
127
|
+
|
|
128
|
+
MIT License - See `package.json` for details
|