Skip to content

Commit 5ab454e

Browse files
committed
Update README.md: Enhance documentation with new features, installation instructions, and error handling improvements. Added requirements for Python 3.13+, clarified usage patterns, and updated function descriptions for text file manipulation tools.
1 parent 325f22d commit 5ab454e

File tree

1 file changed

+78
-53
lines changed

1 file changed

+78
-53
lines changed

README.md

+78-53
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
[![codecov](https://codecov.io/gh/tumf/mcp-text-editor/branch/main/graph/badge.svg?token=52D51U0ZUR)](https://codecov.io/gh/tumf/mcp-text-editor)
44
[![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)
56

67
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.
78

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-
109
## Quick Start for Claude.app Users
1110

1211
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
1817
```json
1918
{
2019
"mcpServers": {
21-
2220
"text-editor": {
2321
"command": "uvx",
2422
"args": [
2523
"mcp-text-editor"
2624
]
27-
},
25+
}
2826
}
2927
}
3028
```
@@ -40,7 +38,8 @@ MCP Text Editor Server is designed to facilitate safe and efficient line-based t
4038
- Optimized for LLM tool integration
4139
- Safe concurrent editing with hash-based validation
4240
- 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.)
4443

4544
## Features
4645

@@ -83,8 +82,20 @@ source .venv/bin/activate # On Windows: .venv\Scripts\activate
8382
uv pip install -e ".[dev]"
8483
```
8584

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+
8691
## Installation
8792

93+
### Run via uvx
94+
95+
```bash
96+
uvx mcp-text-editor
97+
```
98+
8899
### Installing via Smithery
89100

90101
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
94105
```
95106

96107
### Manual Installation
108+
109+
1. Install Python 3.13+
110+
97111
```bash
98-
pip install -e .
112+
pyenv install 3.13.0
113+
pyenv local 3.13.0
99114
```
100115

101-
For development:
116+
2. Install uv (recommended) or pip
102117

103118
```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]"
105128
```
106129

107130
## Usage
@@ -114,7 +137,7 @@ python -m mcp_text_editor
114137

115138
### MCP Tools
116139

117-
The server provides two main tools:
140+
The server provides several tools for text file manipulation:
118141

119142
#### get_text_file_contents
120143

@@ -126,7 +149,8 @@ Get the contents of one or more text files with line range specification.
126149
{
127150
"file_path": "path/to/file.txt",
128151
"line_start": 1,
129-
"line_end": 10
152+
"line_end": 10,
153+
"encoding": "utf-8" // Optional, defaults to utf-8
130154
}
131155
```
132156

@@ -140,7 +164,8 @@ Get the contents of one or more text files with line range specification.
140164
"ranges": [
141165
{"start": 1, "end": 10},
142166
{"start": 20, "end": 30}
143-
]
167+
],
168+
"encoding": "shift_jis" // Optional, defaults to utf-8
144169
},
145170
{
146171
"file_path": "file2.txt",
@@ -178,16 +203,16 @@ Parameters:
178203
"file1.txt": [
179204
{
180205
"content": "Lines 1-10 content",
181-
"start_line": 1,
182-
"end_line": 10,
206+
"start": 1,
207+
"end": 10,
183208
"hash": "sha256-hash-1",
184209
"total_lines": 50,
185210
"content_size": 512
186211
},
187212
{
188213
"content": "Lines 20-30 content",
189-
"start_line": 20,
190-
"end_line": 30,
214+
"start": 20,
215+
"end": 30,
191216
"hash": "sha256-hash-2",
192217
"total_lines": 50,
193218
"content_size": 512
@@ -196,8 +221,8 @@ Parameters:
196221
"file2.txt": [
197222
{
198223
"content": "Lines 5-15 content",
199-
"start_line": 5,
200-
"end_line": 15,
224+
"start": 5,
225+
"end": 15,
201226
"hash": "sha256-hash-3",
202227
"total_lines": 30,
203228
"content_size": 256
@@ -206,39 +231,31 @@ Parameters:
206231
}
207232
```
208233

209-
#### edit_text_file_contents
234+
#### patch_text_file_contents
210235

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.
212237

213238
**Request Format:**
214239

215240
```json
216241
{
217242
"files": [
218243
{
219-
"path": "file1.txt",
244+
"file_path": "file1.txt",
220245
"hash": "sha256-hash-from-get-contents",
246+
"encoding": "utf-8", // Optional, defaults to utf-8
221247
"patches": [
222248
{
223-
"line_start": 5,
224-
"line_end": 8,
249+
"start": 5,
250+
"end": 8,
251+
"range_hash": "sha256-hash-of-content-being-replaced",
225252
"contents": "New content for lines 5-8\n"
226253
},
227254
{
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"
242259
}
243260
]
244261
}
@@ -247,11 +264,11 @@ Edit text file contents with conflict detection. Supports editing multiple files
247264
```
248265

249266
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
251268
2. Patches are applied from bottom to top to handle line number shifts correctly
252269
3. Patches must not overlap within the same file
253270
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
255272
6. File encoding must match the encoding used in get_text_file_contents
256273

257274
**Success Response:**
@@ -261,30 +278,31 @@ Important Notes:
261278
"file1.txt": {
262279
"result": "ok",
263280
"hash": "sha256-hash-of-new-contents"
264-
},
265-
"file2.txt": {
266-
"result": "ok",
267-
"hash": "sha256-hash-of-new-contents"
268281
}
269282
}
270283
```
271284

272-
**Error Response:**
285+
**Error Response with Hints:**
273286

274287
```json
275288
{
276289
"file1.txt": {
277290
"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+
282298
"result": "error",
283299
"reason": "Content hash mismatch - file was modified",
284300
"hash": "current-hash",
285301
"content": "Current file content"
302+
286303
}
287304
}
305+
288306
```
289307
290308
### Common Usage Pattern
@@ -360,26 +378,33 @@ The server handles various error cases:
360378
- Check file and directory permissions
361379
- Ensure the server process has necessary read/write access
362380

363-
2. Hash Mismatch Errors
381+
2. Hash Mismatch and Range Hash Errors
364382
- 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
366390

367-
3. Connection Issues
391+
4. Connection Issues
368392
- Verify the server is running and accessible
369393
- Check network configuration and firewall settings
370394

371-
4. Performance Issues
395+
5. Performance Issues
372396
- Consider using smaller line ranges for large files
373397
- Monitor system resources (memory, disk space)
398+
- Use appropriate encoding for file type
374399

375400
## Development
376401

377402
### Setup
378403

379404
1. Clone the repository
380405
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`
383408

384409
### Code Quality Tools
385410

0 commit comments

Comments
 (0)