Skip to main content
Glama
cygnussystems

cygnus-ssh-mcp

Official

ssh_file_replace_line_multi

Replace an exact line in a remote file with multiple lines or delete it by passing an empty list, using SSH. Fails if the line is missing or not unique.

Instructions

Replace a line in a file with one or more new lines (or delete it, with an empty list). Use this instead of ssh_file_replace_line when you need to insert more than one line, or delete a line without using the separate ssh_file_delete_line_by_content tool.

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. 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_lines: List of new lines to insert in place of the match

    • To replace with multiple lines: use ["first line", "second line", ...]

    • To delete the line entirely: use [] (empty list)

    • To replace with an empty line: use [""]

  • 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': <len(new_lines)>} (or, in the rare edge case where the result is byte-identical to the original file, {'success': True, 'message': 'No changes needed...'} instead). On failure (match not found, match not unique, file not found/unreadable): {'success': False, 'error': str} - not a raised exception. Note: does NOT return file_path in the response.

EXAMPLES: Example 1: Replace a line with multiple lines

{
  "file_path": "/etc/hosts",
  "match_line": "127.0.0.1 localhost",
  "new_lines": ["127.0.0.1 localhost", "127.0.0.1 myhost.local"]
}

Example 2: Delete a line entirely

{
  "file_path": "/etc/nginx/nginx.conf",
  "match_line": "# server_tokens off;",
  "new_lines": []
}

Example 3: Replace with an empty line

{
  "file_path": "/etc/ssh/sshd_config",
  "match_line": "PermitRootLogin yes",
  "new_lines": [""]
}
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.
use_sudoNoUse sudo for the operation
file_pathYesPath to the file to modify
new_linesYesList of new lines to insert in place of the match
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.9/5.0
Behavior5/5

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

No annotations exist, so the description carries the full burden and does: it discloses the uniqueness-match failure mode, that failures return {'success': False, 'error'} rather than raising, the exact success return shape, and the long-running/in_progress handle polling and single-operation 'busy' constraint.

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-loads purpose, then constraints, returns, and examples in a scannable order; every section earns its place. Minor redundancy between the description's force/use_sudo note and the schema's own parameter descriptions, which is the only thing keeping 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, everything an agent needs is present: matching semantics, failure behavior, return shape, sudo/force implications, async fallback, and worked examples. Nothing required for correct invocation is missing.

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

Parameters5/5

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

Goes well beyond the schema by pinning down semantics: match_line is whitespace-trimmed literal text, not a pattern, and must match exactly one line; new_lines encodes delete ([]) vs blank line ([""]); force is deprecated. These distinctions are not derivable from the schema alone.

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+resource ('Replace a line in a file with one or more new lines') and explicitly differentiates itself from ssh_file_replace_line and ssh_file_delete_line_by_content. An agent can distinguish it from the sibling line-editing 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 states when to use this over ssh_file_replace_line ('when you need to insert more than one line, or delete a line'), and routes to ssh_file_find_lines_with_pattern when uniqueness is unverified. Both the alternative and the selecting condition are named.

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