SSH Remote MCP
# π‘οΈ 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
Scored across 12 tools
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.
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.
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.
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.