findAndReplaceTextInDocument
Find and replace EXACT substrings in a document (NOT regex: wildcards and patterns are matched literally). Replaces EVERY occurrence and returns the replacement count; best for renames and repeated phrases. For a single targeted change at a known location, prefer editDocument (anchor patches). Ca...
This record as markdown: /tools/io-stablebaseline-sb/findandreplacetextindocument.md
What findAndReplaceTextInDocument does on Stable Baseline
AI agents use findAndReplaceTextInDocument to create or update resources in Stable Baseline, usually the action step of a workflow, after the agent has gathered context. Every call changes real data in your Stable Baseline environment.
| Parameter | Type | Required | Description |
|---|---|---|---|
find | string | Yes | Text to search for. |
replace | string | Yes | Replacement text. Empty string to delete occurrences. |
projectId | string | — | Optional. Narrows a friendly-id lookup to one project. Only needed when a friendly id is ambiguous — TAS-/IMP-/PLN- ids are numbered per PROJECT, so the same id |
documentId | string | Yes | |
caseSensitive | boolean | — | Case-sensitive matching. Default: true. |
changeSummary | string | — | Version history summary. |
versionTimestamp | number | — | Optional optimistic-lock token from getDocument() or a previous write; validated when provided. (Alias accepted: documentVersionTimestamp.) |
Parameters from the server's own tool schema.
Why findAndReplaceTextInDocument is rated Medium
This tool modifies document content by replacing text substrings. It is a reversible write operation (text can be restored), but the blast radius is medium because it replaces ALL occurrences across the document without regex safeguards, meaning a broad search term could cause widespread unintended modifications to document content.
From the tool's definition Find and replace EXACT substrings in a document... Replaces EVERY occurrence and returns the replacement count
Attacks that exploit this kind of access
The rule that runs findAndReplaceTextInDocument safely
PolicyLayer is an MCP gateway: it sits between your AI agents and Stable Baseline, and checks every tool call against a rule you set before the call runs. Nothing changes on the server itself. For findAndReplaceTextInDocument, this is the rule to start with:
findAndReplaceTextInDocument stays usable, but capped: an agent stuck in a loop can't make hundreds of changes a minute. Everything else on the server is denied unless you say otherwise.
The button opens the PolicyLayer dashboard: create your workspace, connect Stable Baseline, apply this rule, and every findAndReplaceTextInDocument call is checked against it from then on.
Questions about findAndReplaceTextInDocument
Find and replace EXACT substrings in a document (NOT regex: wildcards and patterns are matched literally). Replaces EVERY occurrence and returns the replacement count; best for renames and repeated phrases. For a single targeted change at a known location, prefer editDocument (anchor patches). Case-sensitive by default. Diagrams/images are automatically protected — only document text is affected. Returns document.versionTimestamp (the fresh optimistic-lock token) like every other mutating tool, so you can chain straight into editDocument or the diagram tools. Pass versionTimestamp to opt into optimistic locking (optional here — whole-document find/replace is position-independent). Note: when the replace value contains a <!-- REFERENCE: {...} --> marker (e.g. inserting a user mention), it round-trips losslessly through the editor and triggers notifications if it adds a new user mention. It is categorised as a Write tool in the Stable Baseline MCP Server, which means it can create or modify data. Consider rate limits to prevent runaway writes.
findAndReplaceTextInDocument accepts 7 parameters: find, replace, projectId, documentId, caseSensitive, changeSummary, versionTimestamp. Required: find, replace, documentId. The full parameter table on this page comes from the server's own tool schema.
Register the Stable Baseline MCP server in PolicyLayer and add a rule for findAndReplaceTextInDocument: allow, deny, rate-limit, or require approval. Point your MCP client at the PolicyLayer proxy URL and the rule is enforced on every call, before it reaches Stable Baseline. Nothing to install.
findAndReplaceTextInDocument is a Write tool with medium risk. Write tools should be rate-limited to prevent accidental bulk modifications.
Yes. Add a rate_limit block to the findAndReplaceTextInDocument rule in your PolicyLayer policy. For example, setting max: 10 and window: 60 limits the tool to 10 calls per minute. Rate limits are tracked per agent session and reset automatically.
Set action: deny in the PolicyLayer policy for findAndReplaceTextInDocument. The AI agent will receive a policy violation error and cannot call the tool. You can also include a reason field to explain why the tool is blocked.
findAndReplaceTextInDocument is provided by the Stable Baseline MCP server (https://api.stablebaseline.io/functions/v1/cloud-serve/mcp). PolicyLayer sits as a proxy in front of this server to enforce policies before tool calls reach the server.
More on Stable Baseline, and thousands of servers like it.
This server
Across the catalogue