Skip to main content
Glama
TMYTiMidlY

portal-mcp-server

by TMYTiMidlY

remote_patch

Apply patches to remote files using hash-based conflict detection, so edits fail safely if content changed and can be retried after re-reading.

Instructions

Apply patches to a remote file with hash-based conflict detection.

Workflow:

  1. Call remote_read to obtain content + file_hash + range_hash for each region.

  2. Call remote_patch with the SAME file_hash and per-patch range_hash.

  3. If the file was modified by anyone else in between, this call returns {"result": "error", "reason": "Content hash mismatch ...", "current_file_hash": ...} — re-read and try again. The remote file is untouched.

patches_json must decode to a list of patch objects: [{"start": int, "end": int|null, "contents": str, "range_hash": str}, ...]

Notes:

  • Patches are applied bottom-to-top so line numbers stay valid.

  • Overlapping patches are rejected.

  • Writes are atomic (tmp file + rename) and re-hashed after write.

  • When auto_newline is true, missing trailing newlines on patch contents are auto-appended only if the slice they replace ended with one. The result includes a "warnings" list either way.

  • use_sudo: read+write the file as root, for a root-owned file the SSH user can't touch. Keeps the SAME hash safety + atomicity as the normal path: content is read via sudo cat, staged over SFTP into the user's private home, then placed with one sudo step (cp → temp beside the target → restore owner/group/mode → atomic rename). The target must already exist; the sudo password is resolved out-of-band per host and the result is flagged high_risk. (Implementation note in the README.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYes
pathYes
encodingNoutf-8
use_sudoNo
file_hashYes
auto_newlineNo
patches_jsonYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv4.0.3

TDQS

A4.6/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 succeeds: it discloses atomic write behavior (tmp file + rename), bottom-to-top application, rejection of overlaps, auto_newline semantics, sudo behavior including staging and high_risk flag, exact error response shape, and that the remote file is untouched on mismatch. This is unusually rich behavioral context.

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?

Well-structured with a front-loaded purpose, a numbered workflow, a patches_json format block, and notes. It is somewhat long, but every section adds distinct value for a complex, multi-behavior tool. Minor trimming of the implementation note could tighten it, but nothing is wasted.

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?

Given 7 parameters, 0% schema description coverage, no annotations, and an existing output schema, the description is complete enough: it covers the workflow, error handling, patch format, sudo path, atomicity, and warnings. The remaining implicit items (host, path, encoding) are standard and unlikely to trip an agent.

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 description coverage is 0%, so the description must compensate. It fully specifies patches_json format (list of objects with start, end, contents, range_hash), explains file_hash usage, use_sudo, and auto_newline. Host, path, and encoding are left implicit, but those are largely self-evident; the complex parameters are well covered.

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 ('Apply patches') and resource ('remote file') and distinguishes itself from siblings via the hash-based conflict detection mechanism. An agent can immediately tell this is the safe, hash-verified patch tool rather than a generic shell or transfer tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides an explicit workflow: call remote_read first, then remote_patch with the same file_hash and range_hash. It also explains the retry path on hash mismatch. It does not compare against alternatives like remote_exec or remote_shell, so it lacks explicit when-not-to-use guidance, but the prerequisite flow is clear.

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