Skip to content

Commit 8669c93

Browse files
committed
feat(text_editor.py): add suggestions and hints for alternative text editing methods based on file state to enhance user guidance
1 parent 3117a04 commit 8669c93

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/mcp_text_editor/text_editor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,21 @@ async def edit_file_contents(
401401
"suggestion": "delete",
402402
}
403403

404+
# Set suggestions for alternative tools
405+
suggestion = None
406+
hint = None
407+
if not os.path.exists(file_path) or not current_content:
408+
suggestion = "append"
409+
hint = "For new or empty files, please consider using append_text_file_contents instead"
410+
elif is_insertion:
411+
if start_zero >= len(lines):
412+
suggestion = "append"
413+
hint = "For adding content at the end of file, please consider using append_text_file_contents instead"
414+
else:
415+
suggestion = "insert"
416+
hint = "For inserting content within file, please consider using insert_text_file_contents instead"
417+
418+
# Prepare the content
404419
new_content = contents if contents.endswith("\n") else contents + "\n"
405420
new_lines = new_content.splitlines(keepends=True)
406421

@@ -424,6 +439,8 @@ async def edit_file_contents(
424439
"result": "ok",
425440
"file_hash": new_hash,
426441
"reason": None,
442+
"suggestion": suggestion,
443+
"hint": hint,
427444
}
428445

429446
except FileNotFoundError:

0 commit comments

Comments
 (0)