Skip to main content
Glama
README.md
# πŸ›‘οΈ SSH Remote MCP β€” Matlock Edition

> **"Never trust raw command piping. Verify state forensically. Contain the blast radius."**  
> An enterprise-grade Model Context Protocol (MCP) server engineered with Grab's **Matlock Agent Mindset** for safe, deterministic, and audited remote infrastructure management.

---

## ⚑ The Problem with Commodity SSH MCPs

Traditional SSH MCPs treat the remote server like a dumb `stdin/stdout` pipe:
1. **Blind Execution / Command Injection**: Raw multiline scripts and unescaped quotes corrupt remote configuration files or cause hanging heredocs.
2. **Zero Blast-Radius Control**: A hallucinated `rm -rf /` or recursive permission change runs unconditionally, permanently bricking nodes.
3. **No Forensic Verification**: Commands returning exit code `0` are assumed successful, even when background services fail to bind ports or immediately enter crash loops.
4. **Dangerous Remote File Mutations**: Overwriting remote files without backup snapshots or unified diff inspection leads to silent data loss.
5. **Session Hanging on Long Tasks**: Builds, container pulls, or migrations cause client stdio timeouts.

---

## πŸ›οΈ The Matlock Architecture

```
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚           AI Agent / Client            β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚ JSON-RPC (MCP)
                                           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                 SSH REMOTE MCP                                         β”‚
β”‚                                                                                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ 3-Tier Blast Radius   β”‚  β”‚   Forensic Assertion    β”‚  β”‚   Safe SFTP Engine      β”‚  β”‚
β”‚  β”‚     Containment       β”‚  β”‚         Engine          β”‚  β”‚  (Atomic + Diff + Roll) β”‚  β”‚
β”‚  β”‚                       β”‚  β”‚                         β”‚  β”‚                         β”‚  β”‚
β”‚  β”‚ β€’ Tier 1: Safe Read   β”‚  β”‚ β€’ Port Listening Verify β”‚  β”‚ β€’ Auto .matlock.bak     β”‚  β”‚
β”‚  β”‚ β€’ Tier 2: Mutating    β”‚  β”‚ β€’ Process Liveness Checkβ”‚  β”‚ β€’ Base64 Safe Transfer  β”‚  β”‚
β”‚  β”‚ β€’ Tier 3: Block/Gate  β”‚  β”‚ β€’ File State Check      β”‚  β”‚ β€’ Unified Git Diffs     β”‚  β”‚
β”‚  β”‚   (Safety Bypass Tkn) β”‚  β”‚ β€’ HTTP Health Probe     β”‚  β”‚ β€’ 1-Click Rollback      β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                                                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚   Background Task Envelope       β”‚  β”‚     Multiplexed Session & Profile Store β”‚     β”‚
β”‚  β”‚   (Detached + Poll + Kill)       β”‚  β”‚     (~/.matlock/profiles.json)          β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚ SSH2 / SFTP Keepalive Pool
                                           β–Ό
                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                 β”‚    Remote Host    β”‚
                                 β”‚ (Homelab / Cloud) β”‚
                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## 🧰 Available Tools (10 Primitives)

### 1. Command Execution & Telemetry
| Tool | Description | Matlock Feature |
| :--- | :--- | :--- |
| `ssh_exec` | Executes shell commands on remote target. | 3-Tier classification (`TIER_1_SAFE`, `TIER_2_MUTATING`, `TIER_3_DESTRUCTIVE`), post-flight assertions, exit-code validation. |
| `ssh_host_diagnose` | Gathers a full forensic host telemetry snapshot. | OS, kernel, uptime, load avg, memory (MB), disk usage, Docker containers, listening ports, top processes in 1 roundtrip. |

### 2. Long-Running Task Envelope
| Tool | Description | Matlock Feature |
| :--- | :--- | :--- |
| `ssh_exec_background` | Detaches long tasks into background runner subshells. | Generates task ID, runner script, captures exit codes to disk without hanging MCP stdio. |
| `ssh_task_poll` | Polls background task status. | Process liveness check, exit code inspection, and real-time log tailing. |
| `ssh_task_kill` | Signals or terminates background task. | Supports `SIGTERM` / `SIGKILL` cleanly. |

### 3. Safe Atomic SFTP Primitives
| Tool | Description | Matlock Feature |
| :--- | :--- | :--- |
| `sftp_read_file` | Reads file content with line slicing. | Line range parameters (`startLine`, `endLine`), SHA-256 integrity hash. |
| `sftp_write_safe` | Atomic file write with automatic backup. | Creates `.matlock.bak.<timestamp>`, base64 transfer, atomic swap, and returns a **Unified Diff** (`diff -u`). |
| `sftp_rollback_file` | Restores modified file from backup. | Atomic restoration from `.matlock.bak.latest` or specific backup. |
| `sftp_list_dir` | Structured directory file explorer. | Parsed permissions, owner, size, and modification timestamps. |

### 4. Profile, Key Bootstrap & Credential Isolation
| Tool | Description | Matlock Feature |
| :--- | :--- | :--- |
| `ssh_profile_manage` | Manages saved hosts in `~/.matlock/profiles.json`. | Zero raw private key transmission across MCP parameters; references credentials securely by profile name. |
| `ssh_key_bootstrap` | 1-Click Password to Key Setup. | Tα»± tαΊ‘o SSH key, kαΊΏt nα»‘i bαΊ±ng password, inject vΓ o `authorized_keys`, xΓ‘c minh vΓ  lΖ°u profile khΓ΄ng cαΊ§n gΓ΅ pass nα»―a. |
| `mcp_auto_install` | Universal Agent IDE Installer. | CΓ i Δ‘αΊ·t tα»± Δ‘α»™ng `ssh-remote-mcp` vΓ o mọi IDE (Claude, VS Code, Cursor, Windsurf...). |

---

## πŸ”’ 3-Tier Blast Radius Containment

* **Tier 1 (Safe / Telemetry)**: Read-only inspection (`ls`, `cat`, `df`, `free`, `ps`, `docker ps`, `ss`). Automatically executed.
* **Tier 2 (Mutating)**: System mutations (`mkdir`, `systemctl restart`, `docker compose up -d`, `apt install`). Executed with pre/post flight forensic assertions.
* **Tier 3 (Destructive)**: High-risk operations (`rm -rf /`, `mkfs`, `dd to /dev/sd*`, `shutdown`, `reboot`, `iptables -F`, `kill -9 1`). **Interpreted and BLOCKED before transmission** unless explicit `confirmDangerToken: true` is supplied.

---

## πŸš€ 1-Click Universal Auto-Installer (CΓ i tα»± Δ‘α»™ng cho mọi Agent IDE)

`ssh-remote-mcp` tΓ­ch hợp sαΊ΅n bα»™ **Auto-Installer thΓ΄ng minh**, tα»± Δ‘α»™ng quΓ©t vΓ  cΓ i Δ‘αΊ·t vΓ o **mọi Agent IDE** cΓ³ trΓͺn mΓ‘y tΓ­nh cα»§a bαΊ‘n (Claude Desktop, VS Code Native MCP, Antigravity, Cursor, Windsurf, Cline, Roo Code, Continue, Zed):

```bash
# 1-Click CΓ i Δ‘αΊ·t tα»± Δ‘α»™ng qua NPX (tα»± Δ‘α»™ng nhαΊ­n diện IDE vΓ  cαΊ₯u hΓ¬nh an toΓ n):
npx github:nguyenquocanhz/ssh-remote-mcp install

# HoαΊ·c cΓ i tα»« local repo:
node dist/index.js install

# Xem danh sΓ‘ch cΓ‘c IDE được phΓ‘t hiện trΓͺn mΓ‘y:
npx github:nguyenquocanhz/ssh-remote-mcp list

# CΓ i Δ‘αΊ·t Γ©p buα»™c cho tαΊ₯t cαΊ£ IDE (kể cαΊ£ chΖ°a khởi tαΊ‘o config):
npx github:nguyenquocanhz/ssh-remote-mcp install --all
```

✨ **TΓ­nh nΔƒng an toΓ n cα»§a Auto-Installer:**
- **KhΓ΄ng ghi Δ‘Γ¨ dα»― liệu cΕ©:** Giα»― nguyΓͺn 100% cΓ‘c MCP server Δ‘ang cΓ³ (`zmp-mcp`, `unityMCP`,...).
- **Tα»± Δ‘α»™ng sao lΖ°u:** TαΊ‘o file snapshot `.matlock.bak.<timestamp>` trΖ°α»›c khi chỉnh sα»­a.
- **Hα»— trợ Δ‘a nền tαΊ£ng:** Windows, macOS, Linux.

---

## βš™οΈ CαΊ₯u hΓ¬nh thα»§ cΓ΄ng (Manual Configuration)

NαΊΏu bαΊ‘n muα»‘n cαΊ₯u hΓ¬nh thα»§ cΓ΄ng vΓ o file config cα»§a IDE:

**CΓ‘ch 1: ChαΊ‘y trα»±c tiαΊΏp qua NPX tα»« GitHub:**
```json
{
  "mcpServers": {
    "ssh-remote-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "github:nguyenquocanhz/ssh-remote-mcp"
      ]
    }
  }
}
```

**CΓ‘ch 2: ChαΊ‘y tα»« source code cα»₯c bα»™:**
```bash
cd D:\ssh-remote-mcp
npm install
npm run build
```
CαΊ₯u hΓ¬nh trong `mcp_config.json`:
```json
{
  "mcpServers": {
    "ssh-remote-mcp": {
      "command": "node",
      "args": [
        "D:\\ssh-remote-mcp\\dist\\index.js"
      ]
    }
  }
}
```

---

## πŸ§ͺ Verification & Evidence

Run the integrated automated forensic test suite:
```bash
node test-matlock.js
```

Verified against Homelab Node (`192.168.100.169`):
- βœ… `ssh_host_diagnose`: OS Ubuntu 24.04.5 LTS, 15 Docker containers detected (`zaloapp-backend` healthy on port 8088).
- βœ… `ssh_exec`: Post-flight assertions verified Port 8088 listening and `cloudflared` active.
- βœ… Blast-Radius: Destructive `rm -rf /` blocked by Matlock guardrails.
- βœ… Safe SFTP: Atomic backup created, unified diff generated, rolled back cleanly.
- βœ… Background Envelope: Detached runner script executed `for loop`, polled output, and returned exit code 0.

TDQS

A3.5/5.0

Scored across 12 tools

Disambiguation4/5

Tools are largely distinct by resource and action: foreground vs background execution, task lifecycle, SFTP file operations, diagnostics, profiles, and setup. Minor overlap exists between ssh_profile_manage and ssh_key_bootstrap (both can save profiles), and mcp_auto_install is tangential to remote SSH operations but clearly described.

Naming Consistency4/5

All names use snake_case with consistent resource prefixes (ssh_, sftp_, mcp_). However action ordering varies (ssh_exec vs ssh_task_poll) and mcp_auto_install breaks the prefix-based pattern, so it is not perfectly uniform.

Tool Count5/5

12 tools is well within the ideal range for an SSH remote management server, covering execution, background tasks, file transfer, diagnostics, profile management, and setup without bloat.

Completeness4/5

Core workflows are covered: command exec, background task lifecycle, file read/write/list/rollback, host diagnostics, profile management, key bootstrap, and installer. Missing explicit remote file delete/mkdir/chmod or connection tunneling, but those can be achieved via ssh_exec.

Maintenance

ActivityMaintained
ResponsivenessNo issues