FileWriteOrEdit
Write or edit files on the MCP server by specifying the percentage of changes needed. Use search/replace blocks for minor edits or provide full content for major updates, ensuring precise file modifications.
Instructions
- Writes or edits a file based on the percentage of changes.
- Use absolute path only (~ allowed).
- First write down percentage of lines that need to be replaced in the file (between 0-100) in percentage_to_change
- percentage_to_change should be low if mostly new code is to be added. It should be high if a lot of things are to be replaced.
- If percentage_to_change > 50, provide full file content in text_or_search_replace_blocks
- If percentage_to_change <= 50, text_or_search_replace_blocks should be search/replace blocks.
Instructions for editing files.
Example
Input file
Edit format on the input file
SEARCH/REPLACE block Rules:
- Every "SEARCH" section must EXACTLY MATCH the existing file content, character for character, including all comments, docstrings, whitespaces, etc.
- In a single call the edit blocks should be constructed from top to bottom of the file in a sequence.
- An edit block can't edit over a previous edit in the same tool call.
- Including multiple unique SEARCH/REPLACE blocks if needed.
- Include enough and only enough lines in each SEARCH section to uniquely match each set of lines that need to change.
- Keep SEARCH/REPLACE blocks concise.
- Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
- Include just the changing lines, and a few surrounding lines (0-3 lines) if needed for uniqueness.
- Other than for uniqueness, avoid including those lines which do not change in search (and replace) blocks. Target 0-3 non trivial extra lines per block.
- Preserve leading spaces and indentations in both SEARCH and REPLACE blocks.
Input Schema
Name | Required | Description | Default |
---|---|---|---|
file_path | Yes | #1: absolute file path | |
percentage_to_change | Yes | #2: predict this percentage, calculated as number of existing lines that will have some diff divided by total existing lines. | |
text_or_search_replace_blocks | Yes | #3: content/edit blocks. Must be after #2 in the tool xml | |
thread_id | Yes | #4: thread_id |