Skip to main content
Glama
re-patch

re-patch

by Heretek-RE

re-patch

MCP server for on-disk patching of binary artifacts. Provides:

  • SHA-256 manifest of a binary (so the original can be verified / restored)

  • Byte-level patch application: copy a file, write new_bytes at offset, save the result

  • Manifest-driven restore: read the manifest, copy the original back

The server does not enforce policy — it surfaces an audit log (confirm_legal parameter) so the calling agent records the justification for every patch. The user / run policy is the caller's responsibility.

Why

The 2026-06-05 stress test surfaced a need for an on-disk patch primitive that's:

  • Auditable — every call carries a confirm_legal text the analyst must type in

  • Reversible — the SHA-256 manifest + restore_original tool let the analyst roll back to the exact original bytes

  • Non-destructive — apply_patch writes a copy at dst, not in place; the original at src is never modified

Related MCP server: hashline-mcp

Tools

Tool

What it does

check_patch

Health check — re-patch has no system dependencies; always status: OK

sha256_manifest

Return the SHA-256 of path (hex-encoded)

apply_patch

Copy src to dst, write new_bytes_b64 at offset in dst

restore_original

Copy original (whose SHA-256 matches the manifest) to restore_target

Install

Part of the RE-AI plugin; ./install.sh installs the package. To install standalone:

pip install -e ./servers/re-patch

Run

re-patch                                # stdio transport (default for MCP)
python -m re_patch                      # equivalent

Available Tools

4 tools
apply_patchA

Copy src to dst, then splice new_bytes_b64 at offset.

This is the on-disk patch primitive. The original bytes at src are never modified; the patch is written to a copy at dst. The function returns both the pre-patch and post-patch SHA-256 so the analyst can record the patch's net effect in the report.

Args: src: source file (the original; never modified) dst: destination file (created or overwritten with the patched copy) offset: byte offset into dst at which to write (0-based) new_bytes_b64: base64-encoded bytes to splice in confirm_legal: free-text justification (the audit trail; the server does not enforce policy)

Returns::

{
  "src": "...",
  "dst": "...",
  "src_sha256": "<original>",
  "dst_sha256": "<patched>",
  "src_size": N,
  "dst_size": N,
  "offset": N,
  "patched_bytes": M,
  "confirm_legal": "...",
}

Override-scope contract: this tool is gated behind the run's policy override (see override-scope.md of the active run). The override authorizes on-disk patches only inside Output/<run-id>/patches/; the confirm_legal text must reference the override file and the rationale.

NameRequiredDescriptionDefault
srcYes
dstYes
offsetYes
new_bytes_b64Yes
confirm_legalNo
check_patchA

Return server status + version. Always status: OK — re-patch has no external system dependencies (pure Python stdlib + mcp / pydantic).

NameRequiredDescriptionDefault

No parameters

restore_originalA

Copy original back to restore_target, optionally verifying the original's SHA-256 against expected_sha256 first.

This is the rollback primitive. The function:

  1. Computes the SHA-256 of original.

  2. If expected_sha256 is non-empty, verifies the computed hash matches (refuses to proceed otherwise).

  3. Copies original to restore_target (overwriting).

Args: original: file whose bytes are the canonical "original" (typically the source the patch was applied from) restore_target: file to write the original bytes to (typically the patched copy) expected_sha256: optional hex-encoded SHA-256 to verify original against confirm_legal: free-text justification (audit trail)

Returns::

{
  "original": "...",
  "restore_target": "...",
  "original_sha256": "<hash>",
  "expected_sha256": "<hash>" or null,
  "verified": bool,
  "confirm_legal": "...",
}
NameRequiredDescriptionDefault
originalYes
restore_targetYes
expected_sha256No
confirm_legalNo
sha256_manifestA

Compute the SHA-256 manifest of path.

Args: path: file to hash

Returns::

{
  "path": "...",
  "size": N,
  "sha256": "<64 hex chars>",
}

Use this to record the canonical SHA-256 of the original binary before any patch is applied. The hash is the rollback key: restore_original(original, target, expected_sha256=...) will refuse to proceed if the original's hash has drifted.

NameRequiredDescriptionDefault
pathYes

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 4 tool updatesv0.1.0
    • First observedapply_patch
    • First observedcheck_patch
    • First observedrestore_original
    • First observedsha256_manifest

TDQS

A4.5/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a distinct purpose: applying patches, health check, rollback, and hash computation. No overlap or ambiguity.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern in snake_case (apply_patch, check_patch, restore_original, sha256_manifest).

Tool Count5/5

4 tools is well-scoped for a focused patching utility; each tool is necessary and justified.

Completeness4/5

Core patching workflow (hash, apply, rollback, health) is covered, though a tool to list applied patches is missing.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    Not graded
    maintenance
    A deterministic MCP server that enforces auditable workflows by requiring AI agents to provide structured justifications and obtain human approval for file operations. It provides a secure, tamper-evident pipeline for tracking agent intent and codebase changes through cryptographic signatures and SQLite indexing.
    AGPL 3.0
  • F
    license
    A
    quality
    D
    maintenance
    An MCP server for precise, hash-referenced file editing that enables atomic edits using line:hash references instead of fragile line numbers or full content reproduction.
    2
    -
  • A
    license
    Not graded
    quality
    B
    maintenance
    A filesystem MCP server that journals every file operation (write, delete, move, mkdir) and outbound commands (exec, http) into an append-only ledger, enabling undo and compensation of actions.
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    A local-first, model-neutral MCP server for collecting and normalizing change-scoped release evidence. It provides deterministic Git change summaries, evidence collection, and review bundles for agent review.
    7
    7 npm
    Apache 2.0