Skip to main content
Glama

Surgical find-and-replace in an Overleaf doc

find_and_replace

Replace one occurrence or all matches of an exact string in an Overleaf document for targeted single edits, preserving the rest of the file and avoiding full-document re-emission.

Instructions

Replace one occurrence — or all, with replace_all: true — of old_string with new_string in a doc, without re-emitting the rest of the file. By default old_string must be unique; ambiguous matches are returned with line:column locations so you can extend the match. Submits the minimal OT operation through the same pathway as edit_file, so by default it lands as a pending suggestion in Overleaf's Review panel (track:'on'). If path is omitted, defaults to the project's root doc. USE WHEN: a SINGLE targeted edit (one typo, one label rename, one heading change) in a large doc — saves tokens vs. re-emitting the body and avoids accidental whitespace drift. AVOID FOR BATCH WORK: for multiple substitutions (e.g. converting many words, applying a style guide across a chapter) prefer ONE edit_file call with all changes computed client-side. Each find_and_replace is its own round-trip with its own race window, its own tracked-change entry, and its own cache-sync cycle — calling it N times for N small changes amplifies the failure modes that one batched edit_file would avoid.

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": {
      "old_string": "<old_string>",
      "new_string": "<new_string>"
    },
    "name": "find_and_replace"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathNoProject-relative path of the doc to edit, e.g. 'main.tex'. If omitted, defaults to the project's root doc.
trackNoTracked-changes mode. This is a client *request*, not a guarantee — when the project has `track_changes_on_for_me: true` (visible in `open_project`'s response), the server forces tracking regardless of what you pass, and the tool response will report `tracked: true, track_overridden: true`. Don't tell the user 'this will be untracked' without first checking that flag from `open_project`. Modes: 'on' (default) — explicitly request tracking; edit lands as a pending suggestion in Overleaf's Review panel. 'off' — request a direct untracked write (may be overridden as above). 'auto' — track iff the project's tc setting says so.on
new_stringYesReplacement text. May be empty (effectively a delete).
old_stringYesExact substring to find — must match byte-for-byte including whitespace. Must be unique in the doc unless `replace_all` is true.
project_idNoOverleaf project id from list_projects or open_project. Opens the project if it is not already active. Pass it on every call when MCP sessions may change between calls. Writes without it only go to the project last confirmed by open_project or by a write naming it.
replace_allNoIf true, replace every occurrence of `old_string`. If false (default), `old_string` must match exactly once — multi-match returns a list of locations so you can disambiguate with a longer `old_string`.
strict_versionNoIf true, re-fetch the doc version before sending the edit and refuse if the cached baseline is stale. Catches races from parallel agents (each MCP process has its own cache) or a concurrently open Overleaf web editor at the cost of one extra round-trip. Without this, the server's OT transform handles stale-version edits silently, which can land the op in an unexpected location or collapse it to a no-op. Recommended when several agents may be editing the same project.
expected_versionNoOptional safety check. If the doc's current version differs, the edit is rejected.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.4.0
    • addedInput schema / properties / project_id
      Added value: +{
      +  "description": "Overleaf project id from list_projects or open_project. Opens the project if it is not already active. Pass it on every call when MCP sessions may change between calls. Writes without it only go to the project last confirmed by open_project or by a write naming it.",
      +  "minLength": 8,
      +  "type": "string"
      +}
  2. First observedv0.3.5

TDQS

A4.7/5.0
Behavior5/5

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

With no annotations supplied, the description carries the full burden and does so: it discloses that the edit lands as a pending suggestion in Overleaf's Review panel under track:'on', that ambiguity returns line:column locations instead of writing, and that the operation goes through the same OT pathway as `edit_file`. The batching paragraph also surfaces the failure modes (race windows, tracked-change proliferation) an agent would otherwise only discover at runtime.

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?

Front-loaded with the core action and the default-uniqueness rule before any caveats, and the USE WHEN / AVOID FOR BATCH WORK headers make it scannable. The batch-work paragraph is long and slightly repetitive (round-trip, race window, tracked entry, cache sync), but each clause names a distinct cost, so it earns most of its length.

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

Completeness4/5

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

For an 8-parameter mutation tool with no annotations and no output schema, the description covers the safety profile (tracking, ambiguity rejection), the alternative (batched `edit_file`), and some response signal (`tracked: true, track_overridden: true`, line:column locations). It never describes the shape of a successful edit response or how to read the returned version, which is the one gap left by the absent output schema.

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 100%, so the baseline is 3; the description nonetheless reinforces the semantics that matter operationally — `replace_all: true` versus default uniqueness, the `path` fallback to the project root doc, and the tracked-changes default. It stops short of adding much beyond the schema on `strict_version`/`expected_version`, which are the most subtle parameters, but the ambiguity/line:column behavior is a genuine addition.

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?

Names a specific verb and resource (replace one or all occurrences of `old_string` with `new_string` in a doc) and pins down the key differentiator from the sibling: it submits a minimal OT op without re-emitting the file body, via the same pathway as `edit_file`. An agent can distinguish this from `edit_file` without opening either 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?

Explicit USE WHEN (a single targeted edit in a large doc) and an explicit AVOID FOR BATCH WORK section that names the alternative (`edit_file` with client-side computed changes) and explains why: N round-trips, N race windows, N tracked-change entries, N cache-sync cycles. This is exactly the when/when-not/alternative structure that prevents misuse.

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