Skip to main content
Glama

Edit a file in the local clone

edit_file
Destructive

Edit one file in an Overleaf project's local clone: replace an exact snippet, swap a whole LaTeX section by title, write a new file, or append to the end, then review and publish.

Instructions

Change one file in the project's local clone; action picks how. replace_text replaces an exact snippet, findText, with replaceWith: findText must match exactly, whitespace and newlines included, and occur once unless replaceAll is set, and replaceWith is inserted literally, so $$, $& and $1 stay as written. Prefer it for a targeted change, since nothing outside the snippet is touched. replace_section replaces one whole section of a .tex file, found by sectionTitle as read_file finds it, from its heading to the next heading of the same or a shallower level, never swallowing trailing matter such as \end{document} or the bibliography; content replaces that range line for line, so it must start with the sectioning command itself or the heading is lost, and should end with a newline to keep the blank line before the next heading. write creates the file, with any missing parent directories, or overwrites it entirely with content, exactly as given, as UTF-8, with no trailing newline added; use it for a new file, since for an existing one the other actions cannot drop text you did not mean to rewrite. append adds content at the end of an existing file and leaves every line above it untouched: content starts on a new line and is written exactly as given, so end it with a newline to keep one at the end of the file. A missing file is refused, since write is the action that creates one. expectedRevision makes any action a guarded edit, refused if the file changed since that read or, for write, no longer exists. path must be relative and stay inside the project; absolute paths, .. escapes and the .git directory are refused. Pulls from Overleaf first, then edits only the local clone: review the result with read_project (view changes) and publish it with push_changes. If the snippet or the section is not found, or the snippet occurs several times without replaceAll, nothing changes and the reply gives the count or lists the section titles. Returns what was replaced, written or appended.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "action": "<action>",
      "path": "<path>"
    },
    "name": "edit_file"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathYesEvery action: path of the file relative to the project root, e.g. sections/intro.tex. Must stay inside the project.
actionYesHow to edit: replace_text (an exact snippet), replace_section (a whole section, by title), write (the whole file) or append (add to the end of the file).
contentNoreplace_section, write and append, required. For replace_section, the section's full replacement, starting with its own sectioning command, e.g. \section{Introduction} followed by the new body. For write, the complete new contents of the file. For append, the text to add after the file's last line.
projectNoWhich project to use: its Overleaf address, its 24-character id, or a registered project name. Omit to use the default project.
findTextNoreplace_text, required: exact text to find, matched literally including whitespace and newlines. Not a regular expression.
replaceAllNoreplace_text only: replace every occurrence instead of requiring exactly one match (default false). Only set this when replacing all of them is intended.
replaceWithNoreplace_text, required: text to put in its place. An empty string deletes the snippet.
sectionTitleNoreplace_section, required: title of the section to replace, as it appears in the sectioning command. Matched case-insensitively, with a substring fallback; read_project (view outline) lists the titles.
expectedRevisionNoEvery action, optional guard: the 64-character revision hash returned by read_file with mode=full or mode=smart for this same file. When given, the edit is refused if the file changed since that read, for example because pulling from Overleaf brought in a collaborator's version. Pass it whenever the edit depends on content you read earlier; leave it out when creating a file.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv0.5.0

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Although annotations already mark this as destructive, non-read-only, non-idempotent, and open-world, the description adds substantial behavior beyond them. It discloses exact-match requirements, literal replacement semantics, no-op failure behavior, path containment rules, Overleaf pull-before-edit behavior, and guarded edits via expectedRevision.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with action selection and every major sentence carries operational meaning, but the single dense paragraph makes it harder to scan than a structured list would be. It is appropriately sized for a complex nine-parameter mutation tool, with only minor redundancy in the action explanations.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is a complex editing operation with no output schema, so the description must carry return and failure semantics, which it does. It explains what is returned, when nothing changes, how failures are reported with counts or section titles, and how edits interact with the local clone and Overleaf.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is already 100%, so the baseline is 3, but the description adds meaning that the schema does not fully convey. It explains exact whitespace/newline matching for findText, literal handling of $$, $& and $1, line-for-line section replacement, required leading sectioning command, and newline implications for content.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: it changes one file in the project's local clone. It immediately distinguishes the four actions by purpose (replace_text, replace_section, write, append), so an agent can identify both the tool and the sub-operation without opening the schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives explicit when-to-use guidance for each action: prefer replace_text for targeted changes, replace_section for whole .tex sections, write for new files, and append to add at the end. It also names alternatives and workflow steps, including reviewing with read_project and publishing with push_changes.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.