Skip to main content
Glama

Replace exact text in a file

replace_text
Destructive

Replace one exact text snippet in an Overleaf project file with new content, editing only that match and leaving the rest of the file untouched.

Instructions

Replace an exact snippet of text in a project file. Prefer it over write_file and edit_section for a targeted change: nothing outside the snippet is touched. findText must match exactly, whitespace and newlines included, and occur once unless replaceAll is set; replaceWith is inserted literally, so $$, $& and $1 stay as written. If the snippet is missing, or occurs several times without replaceAll, nothing changes and the reply gives the count; widen findText with surrounding text to make it unique. Pulls from Overleaf first, then edits only the local clone; push_changes publishes it. Returns how many occurrences were replaced.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath relative to the project root.
projectNoWhich project to use: its Overleaf address, its 24-character id, or a registered project name. Omit to use the default project.
findTextYesExact text to find, matched literally including whitespace and newlines. Not a regular expression.
replaceAllNoReplace every occurrence instead of requiring exactly one match (default false). Only set this when replacing all of them is intended.
replaceWithYesText to put in its place. Empty string deletes the snippet.
expectedRevisionNoOptional 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.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.3.8

TDQS

A4.9/5.0
Behavior5/5

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

Annotations only declare the safety profile (destructive, non-idempotent, open-world). The description goes well beyond: it explains that edits land only in the local clone until push_changes runs, that replaceWith is inserted literally with no $ substitution, that a failed match changes nothing and returns a count, and what the return value is. This is rich behavioral context an agent cannot get from structured fields.

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

Conciseness5/5

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

Front-loads purpose and sibling preference, then failure modes, then the Overleaf/local/push lifecycle, then the return value. Dense but every sentence carries distinct information; no filler.

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?

For a 6-param destructive mutation with no output schema, the description covers the sync model, failure behavior, guard parameter intent, and return value. Nothing an agent needs to invoke it safely is missing.

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

Parameters4/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 real meaning beyond it: the literal-insertion rule for replaceWith ($$, $&, $1 stay as written), the exactness/uniqueness constraint on findText, and the remedy of widening findText. These go past the schema's phrasing.

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?

States a specific verb and resource ('Replace an exact snippet of text in a project file') and immediately differentiates from siblings by naming write_file and edit_section. An agent can distinguish this from the other mutating tools without opening any 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?

Explicitly says to prefer it over write_file and edit_section for a targeted change, and states the when-not condition (snippet missing or occurring several times without replaceAll). It also names the follow-up tool (push_changes) needed to publish.

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