Skip to main content
Glama
lin2000wl

Serena MCP Server

by lin2000wl

replace_regex

Replace text patterns in files using regular expressions to modify code or content efficiently. Use wildcards for multi-line replacements and avoid specifying exact content.

Instructions

Replaces one or more occurrences of the given regular expression. This is the preferred way to replace content in a file whenever the symbol-level tools are not appropriate. Even large sections of code can be replaced by providing a concise regular expression of the form "beginning.*?end-of-text-to-be-replaced". Always try to use wildcards to avoid specifying the exact content of the code to be replaced, especially if it spans several lines.

IMPORTANT: REMEMBER TO USE WILDCARDS WHEN APPROPRIATE! I WILL BE VERY UNHAPPY IF YOU WRITE LONG REGEXES WITHOUT USING WILDCARDS INSTEAD!.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
relative_pathYesThe relative path to the file.
regexYesA Python-style regular expression, matches of which will be replaced. Dot matches all characters, multi-line matching is enabled.
replYesThe string to replace the matched content with, which may contain backreferences like \1, \2, etc.
allow_multiple_occurrencesNoIf True, the regex may match multiple occurrences in the file and all of them will be replaced. If this is set to False and the regex matches multiple occurrences, an error will be returned (and you may retry with a revised, more specific regex).
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by explaining key behavioral aspects: it's a destructive operation (replaces content), handles multiple occurrences (with the allow_multiple_occurrences parameter), and provides practical advice about regex patterns. However, it doesn't mention error handling or file permissions.

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

Conciseness3/5

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

The description is appropriately sized but has structural issues. The first paragraph is well-structured, but the second paragraph with ALL CAPS and emotional language ('I WILL BE VERY UNHAPPY') is unprofessional and redundant with the first paragraph's advice about wildcards.

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 a destructive file operation with no annotations and no output schema, the description provides good context about when to use it, behavioral characteristics, and practical regex advice. It could be more complete by mentioning error conditions or what happens when the file doesn't exist, but covers the essential aspects well.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds some context about regex patterns ('beginning.*?end-of-text-to-be-replaced') and wildcard usage, but doesn't provide additional parameter-specific semantics beyond what's in the schema.

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 clearly states the tool's purpose: 'Replaces one or more occurrences of the given regular expression' and specifies it's for file content replacement. It distinguishes from siblings like 'replace_lines' and 'replace_symbol_body' by emphasizing regex-based replacement when symbol-level tools aren't appropriate.

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?

The description provides explicit guidance on when to use this tool ('whenever the symbol-level tools are not appropriate') and offers specific usage advice about preferring wildcards over long regexes. It also distinguishes from sibling tools by mentioning the alternative symbol-level approaches.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lin2000wl/Serena-cursor-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server