Skip to main content
Glama
cygnussystems

cygnus-ssh-mcp

Official

ssh_file_replace_line

Replace an exact line in a remote file via SSH, requiring a unique match. Fails with an error if the match is missing or ambiguous, preventing unintended edits.

Instructions

Replace a line in a file with a new line. match_line must match EXACTLY ONE line in the file (whitespace-trimmed, literal text - not a pattern); if it matches zero lines or more than one, the operation fails with a descriptive error rather than guessing which line you meant. Use ssh_file_find_lines_with_pattern first if you're not sure the line is unique.

PARAMETERS:

  • file_path: Path to the file to modify

  • match_line: Exact line content to match and replace (whitespace-trimmed)

  • new_line: New line to insert in place of the match

  • use_sudo: Use sudo for the operation (default: false)

  • force: No longer needed (kept for compatibility) - use_sudo reads root-only files with sudo (default: false)

RETURNS: On success: {'success': True, 'lines_written': 1} (or, in the rare edge case where new_line is identical to the matched line, {'success': True, 'message': 'No changes needed...'} instead - nothing to write). On failure (match not found, match not unique, file not found/unreadable): {'success': False, 'error': str} - not a raised exception. Note: unlike some other file tools, this does NOT return file_path in the response.

EXAMPLES: Example 1: Replace a commented line with an active configuration

{
  "file_path": "/etc/ssh/sshd_config",
  "match_line": "#ClientAliveInterval 0",
  "new_line": "ClientAliveInterval 300"
}

Note: To delete a line entirely, use the dedicated ssh_file_delete_line_by_content tool instead. To replace/insert MULTIPLE lines in one call, use ssh_file_replace_line_multi instead.

Long-running calls: if this takes longer than the server's wait cap (default 50s), it
returns {"status": "in_progress", "handle_id": ...} instead of the result - the work keeps
running. Get the result by polling ssh_cmd_check_status(handle_id=...), which returns this
tool's normal response once finished. Do not call it again meanwhile. Only one such
operation runs at a time; another one started meanwhile fails with a 'busy' error.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
forceNoNo longer needed (kept for compatibility): with use_sudo=true the file is read with sudo when the user can't read it. If it can't be read at all, the edit fails - it never reports success without having seen the file.
new_lineYesNew line to insert in place of the match
use_sudoNoUse sudo for the operation
file_pathYesPath to the file to modify
match_lineYesExact line content to match and replace

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.6.1
    • changedInput schema / properties / force / description
      Previous value: -"Force operation even if file can't be read (sudo only)"New value: +"No longer needed (kept for compatibility): with use_sudo=true the file is read with sudo when the user can't read it. If it can't be read at all, the edit fails - it never reports success without having seen the file."
  2. First observedv1.3.0

TDQS

A4.8/5.0
Behavior5/5

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

With no annotations, the description carries the full burden and does so: exact/literal matching semantics, whitespace trimming, failure mode returns a {'success': False, 'error': ...} dict rather than raising, sudo read behavior, the deprecation of force, and the long-running/in_progress handle + polling + single-concurrency 'busy' contract.

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 contract and well-sectioned (params, returns, examples), but the force explanation is stated twice (parameter list and schema-adjacent text) and the long-running paragraph is dense. Minor redundancy keeps it from a 5.

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 mutation tool with no annotations, the definition covers match semantics, failure behavior, sudo/auth implications, an example, sibling routing, and the async in_progress flow. Nothing an agent needs to invoke it correctly 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 100%, so 3 is the baseline, but the description adds real meaning beyond it: match_line is whitespace-trimmed literal text (not a regex), and force is a compatibility no-op whose semantics have moved to use_sudo. That extra nuance justifies a 4.

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 precise verb+resource (replace one line in a file) and immediately distinguishes itself from the multi-line and delete-line siblings by name. An agent can route correctly 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?

Gives explicit preconditions (match_line must match exactly one line; use ssh_file_find_lines_with_pattern first if uniqueness is uncertain) and names the alternatives for other cases (ssh_file_delete_line_by_content, ssh_file_replace_line_multi). Nothing is left to inference.

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