2
2
3
3
[ ![ codecov] ( https://codecov.io/gh/tumf/mcp-text-editor/branch/main/graph/badge.svg?token=52D51U0ZUR )] ( https://codecov.io/gh/tumf/mcp-text-editor )
4
4
[ ![ smithery badge] ( https://smithery.ai/badge/mcp-text-editor )] ( https://smithery.ai/server/mcp-text-editor )
5
+ [ ![ Glama MCP Server] ( https://glama.ai/mcp/servers/k44dnvso10/badge )] ( https://glama.ai/mcp/servers/k44dnvso10 )
5
6
6
7
A Model Context Protocol (MCP) server that provides line-oriented text file editing capabilities through a standardized API. Optimized for LLM tools with efficient partial file access to minimize token usage.
7
8
8
- <a href =" https://glama.ai/mcp/servers/k44dnvso10 " ><img width =" 380 " height =" 200 " src =" https://glama.ai/mcp/servers/k44dnvso10/badge " alt =" mcp-text-editor MCP server " /></a >
9
-
10
9
## Quick Start for Claude.app Users
11
10
12
11
To use this editor with Claude.app, add the following configuration to your prompt:
@@ -18,13 +17,12 @@ code ~/Library/Application\ Support/Claude/claude_desktop_config.json
18
17
``` json
19
18
{
20
19
"mcpServers" : {
21
-
22
20
"text-editor" : {
23
21
"command" : " uvx" ,
24
22
"args" : [
25
23
" mcp-text-editor"
26
24
]
27
- },
25
+ }
28
26
}
29
27
}
30
28
```
@@ -40,7 +38,8 @@ MCP Text Editor Server is designed to facilitate safe and efficient line-based t
40
38
- Optimized for LLM tool integration
41
39
- Safe concurrent editing with hash-based validation
42
40
- Atomic multi-file operations
43
- - Robust error handling and recovery mechanisms
41
+ - Robust error handling with custom error types
42
+ - Comprehensive encoding support (utf-8, shift_jis, latin1, etc.)
44
43
45
44
## Features
46
45
@@ -83,8 +82,20 @@ source .venv/bin/activate # On Windows: .venv\Scripts\activate
83
82
uv pip install -e " .[dev]"
84
83
```
85
84
85
+ ## Requirements
86
+
87
+ - Python 3.13+
88
+ - POSIX-compliant operating system (Linux, macOS, etc.) or Windows
89
+ - File system permissions for read/write operations
90
+
86
91
## Installation
87
92
93
+ ### Run via uvx
94
+
95
+ ``` bash
96
+ uvx mcp-text-editor
97
+ ```
98
+
88
99
### Installing via Smithery
89
100
90
101
To install Text Editor Server for Claude Desktop automatically via [ Smithery] ( https://smithery.ai/server/mcp-text-editor ) :
@@ -94,14 +105,26 @@ npx -y @smithery/cli install mcp-text-editor --client claude
94
105
```
95
106
96
107
### Manual Installation
108
+
109
+ 1 . Install Python 3.13+
110
+
97
111
``` bash
98
- pip install -e .
112
+ pyenv install 3.13.0
113
+ pyenv local 3.13.0
99
114
```
100
115
101
- For development:
116
+ 2 . Install uv (recommended) or pip
102
117
103
118
``` bash
104
- pip install -e " .[dev]"
119
+ curl -LsSf https://astral.sh/uv/install.sh | sh
120
+ ```
121
+
122
+ 3 . Create virtual environment and install dependencies
123
+
124
+ ``` bash
125
+ uv venv
126
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
127
+ uv pip install -e " .[dev]"
105
128
```
106
129
107
130
## Usage
@@ -114,7 +137,7 @@ python -m mcp_text_editor
114
137
115
138
### MCP Tools
116
139
117
- The server provides two main tools:
140
+ The server provides several tools for text file manipulation :
118
141
119
142
#### get_text_file_contents
120
143
@@ -126,7 +149,8 @@ Get the contents of one or more text files with line range specification.
126
149
{
127
150
"file_path" : " path/to/file.txt" ,
128
151
"line_start" : 1 ,
129
- "line_end" : 10
152
+ "line_end" : 10 ,
153
+ "encoding" : " utf-8" // Optional, defaults to utf-8
130
154
}
131
155
```
132
156
@@ -140,7 +164,8 @@ Get the contents of one or more text files with line range specification.
140
164
"ranges" : [
141
165
{"start" : 1 , "end" : 10 },
142
166
{"start" : 20 , "end" : 30 }
143
- ]
167
+ ],
168
+ "encoding" : " shift_jis" // Optional, defaults to utf-8
144
169
},
145
170
{
146
171
"file_path" : " file2.txt" ,
@@ -178,16 +203,16 @@ Parameters:
178
203
"file1.txt" : [
179
204
{
180
205
"content" : " Lines 1-10 content" ,
181
- "start_line " : 1 ,
182
- "end_line " : 10 ,
206
+ "start " : 1 ,
207
+ "end " : 10 ,
183
208
"hash" : " sha256-hash-1" ,
184
209
"total_lines" : 50 ,
185
210
"content_size" : 512
186
211
},
187
212
{
188
213
"content" : " Lines 20-30 content" ,
189
- "start_line " : 20 ,
190
- "end_line " : 30 ,
214
+ "start " : 20 ,
215
+ "end " : 30 ,
191
216
"hash" : " sha256-hash-2" ,
192
217
"total_lines" : 50 ,
193
218
"content_size" : 512
@@ -196,8 +221,8 @@ Parameters:
196
221
"file2.txt" : [
197
222
{
198
223
"content" : " Lines 5-15 content" ,
199
- "start_line " : 5 ,
200
- "end_line " : 15 ,
224
+ "start " : 5 ,
225
+ "end " : 15 ,
201
226
"hash" : " sha256-hash-3" ,
202
227
"total_lines" : 30 ,
203
228
"content_size" : 256
@@ -206,39 +231,31 @@ Parameters:
206
231
}
207
232
```
208
233
209
- #### edit_text_file_contents
234
+ #### patch_text_file_contents
210
235
211
- Edit text file contents with conflict detection. Supports editing multiple files in a single operation.
236
+ Apply patches to text files with robust error handling and conflict detection. Supports editing multiple files in a single operation.
212
237
213
238
** Request Format:**
214
239
215
240
``` json
216
241
{
217
242
"files" : [
218
243
{
219
- "path " : " file1.txt" ,
244
+ "file_path " : " file1.txt" ,
220
245
"hash" : " sha256-hash-from-get-contents" ,
246
+ "encoding" : " utf-8" , // Optional, defaults to utf-8
221
247
"patches" : [
222
248
{
223
- "line_start" : 5 ,
224
- "line_end" : 8 ,
249
+ "start" : 5 ,
250
+ "end" : 8 ,
251
+ "range_hash" : " sha256-hash-of-content-being-replaced" ,
225
252
"contents" : " New content for lines 5-8\n "
226
253
},
227
254
{
228
- "line_start" : 15 ,
229
- "line_end" : 15 ,
230
- "contents" : " Single line replacement\n "
231
- }
232
- ]
233
- },
234
- {
235
- "path" : " file2.txt" ,
236
- "hash" : " sha256-hash-from-get-contents" ,
237
- "patches" : [
238
- {
239
- "line_start" : 1 ,
240
- "line_end" : 3 ,
241
- "contents" : " Replace first three lines\n "
255
+ "start" : 15 ,
256
+ "end" : null , // null means end of file
257
+ "range_hash" : " sha256-hash-of-content-being-replaced" ,
258
+ "contents" : " Content to append\n "
242
259
}
243
260
]
244
261
}
@@ -247,11 +264,11 @@ Edit text file contents with conflict detection. Supports editing multiple files
247
264
```
248
265
249
266
Important Notes:
250
- 1 . Always get the current hash using get_text_file_contents before editing
267
+ 1 . Always get the current hash and range_hash using get_text_file_contents before editing
251
268
2 . Patches are applied from bottom to top to handle line number shifts correctly
252
269
3 . Patches must not overlap within the same file
253
270
4 . Line numbers are 1-based
254
- 5 . If original content ends with newline, ensure patch content also ends with newline
271
+ 5 . ` end: null ` can be used to append content to the end of file
255
272
6 . File encoding must match the encoding used in get_text_file_contents
256
273
257
274
** Success Response:**
@@ -261,30 +278,31 @@ Important Notes:
261
278
"file1.txt" : {
262
279
"result" : " ok" ,
263
280
"hash" : " sha256-hash-of-new-contents"
264
- },
265
- "file2.txt" : {
266
- "result" : " ok" ,
267
- "hash" : " sha256-hash-of-new-contents"
268
281
}
269
282
}
270
283
```
271
284
272
- ** Error Response:**
285
+ ** Error Response with Hints :**
273
286
274
287
``` json
275
288
{
276
289
"file1.txt" : {
277
290
"result" : " error" ,
278
- "reason" : " File not found" ,
279
- "hash" : null
280
- },
281
- "file2.txt" : {
291
+ "reason" : " Content hash mismatch" ,
292
+ "suggestion" : " get" , // Suggests using get_text_file_contents
293
+ "hint" : " Please run get_text_file_contents first to get current content and hashes"
294
+ }
295
+ }
296
+ ```
297
+
282
298
"result": "error",
283
299
"reason": "Content hash mismatch - file was modified",
284
300
"hash": "current-hash",
285
301
"content": "Current file content"
302
+
286
303
}
287
304
}
305
+
288
306
```
289
307
290
308
### Common Usage Pattern
@@ -360,26 +378,33 @@ The server handles various error cases:
360
378
- Check file and directory permissions
361
379
- Ensure the server process has necessary read/write access
362
380
363
- 2 . Hash Mismatch Errors
381
+ 2 . Hash Mismatch and Range Hash Errors
364
382
- The file was modified by another process
365
- - Fetch latest content and retry the operation
383
+ - Content being replaced has changed
384
+ - Run get_text_file_contents to get fresh hashes
385
+
386
+ 3 . Encoding Issues
387
+ - Verify file encoding matches the specified encoding
388
+ - Use utf-8 for new files
389
+ - Check for BOM markers in files
366
390
367
- 3 . Connection Issues
391
+ 4 . Connection Issues
368
392
- Verify the server is running and accessible
369
393
- Check network configuration and firewall settings
370
394
371
- 4 . Performance Issues
395
+ 5 . Performance Issues
372
396
- Consider using smaller line ranges for large files
373
397
- Monitor system resources (memory, disk space)
398
+ - Use appropriate encoding for file type
374
399
375
400
## Development
376
401
377
402
### Setup
378
403
379
404
1 . Clone the repository
380
405
2 . Create and activate a Python virtual environment
381
- 3 . Install development dependencies: ` pip install -e ".[dev]" `
382
- 4 . Run tests: ` pytest `
406
+ 3 . Install development dependencies: ` uv pip install -e ".[dev]"`
407
+ 4 . Run tests: ` make all `
383
408
384
409
### Code Quality Tools
385
410
0 commit comments