ssh_file_get_context_around_line
Show the lines before and after a target line in a remote file via SFTP, so you can inspect context before editing. Requires an exact, unique line match.
Instructions
Get lines before and after a line, to see it in context before editing. Like the
line-editing tools (ssh_file_replace_line and siblings), match_line must match
exactly one line in the file (whitespace-trimmed, literal text, not a pattern) -
use ssh_file_find_lines_with_pattern first if you're not sure the line is unique.
Reads the file via SFTP and matches locally (same as ssh_file_find_lines_with_pattern) - Unicode/non-ASCII content is safe on all platforms, including Windows.
Returns:
On a unique match: {'match_found': True, 'match_line_number': int, 'context_block': [{'line_number': int, 'content': str}, ...]} (the matched
line plus context lines before/after).
If the line isn't found, or matches more than once: {'match_found': False, 'error': str} - for a multi-match error, also includes 'matches' (every
matching line, so you can pick a more specific match_line).
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
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | Number of lines before and after to include | |
| use_sudo | No | Use sudo for the operation | |
| file_path | Yes | Path to the file | |
| match_line | Yes | Exact line content to match |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||