
Product
Microsoft Teams Notifications Are Now Available in Socket
Socket can now send alerts and supply chain attack notifications to Microsoft Teams, with filters that route the right updates to each channel.
ssh-session-mcp
Advanced tools
Persistent SSH PTY session manager for MCP clients with actor-aware input tracking, terminal-style dashboard rendering, and automatic session cleanup.
中文文档: 简体中文
Persistent SSH PTY session manager for MCP clients. Users and AI agents share one SSH terminal — AI sends commands via MCP tools, users type in the browser terminal, input sources are visually distinguished.
SSH_MCP_INSTANCE values so multiple AI agents do not interfere with each otherssh-retry tool for flaky commands with exponential/fixed backoffssh-session-diagnostics reports terminal mode, lock state, viewer state, running command metadata, and buffer trim warningsssh-session-history provides line-numbered history across SSH output, agent input, user input, and lifecycle eventsnpm install -g ssh-session-mcp
Or from source:
git clone https://github.com/Zw-awa/ssh-session-mcp.git
cd ssh-session-mcp
npm install && npm run build
cp .env.example .env
# Edit .env with your SSH credentials
SSH_HOST=192.168.1.100
SSH_PORT=22
SSH_USER=username
SSH_PASSWORD=your-password
# Or use SSH_KEY=/path/to/private/key (recommended)
VIEWER_PORT=auto
AUTO_OPEN_TERMINAL=false
SSH_MCP_MODE=safe
Optional multi-device config:
{
"defaultDevice": "board-a",
"devices": [
{
"id": "board-a",
"host": "192.168.10.58",
"port": 22,
"user": "orangepi",
"auth": { "passwordEnv": "BOARD_A_PASSWORD" },
"defaults": {
"term": "xterm-256color",
"cols": 120,
"rows": 40,
"autoOpenViewer": true,
"viewerMode": "browser"
}
}
]
}
Save it as ssh-session-mcp.config.json in the repo root, or pass --config=/path/to/config.json.
Important:
E:\\XSmartcar\\tools\\ssh-mcp, then E:\\other-project\\ssh-session-mcp.config.json will not be discovered automatically.SSH_MCP_CONFIG=/path/to/config.json or start the server with --config=/path/to/config.json.auth.passwordEnv and auth.keyPath."auth": { "password": "secret" } are invalid and will fail schema validation.passwordEnv, put the real secret in .env or the parent process environment, for example BOARD_A_PASSWORD=orangepi.Config resolution order:
--config=/path/to/config.jsonssh-session-mcp.config.json.env single-device fallbackThis means a config file stored in another workspace is ignored unless you point to it explicitly with SSH_MCP_CONFIG or --config.
Manage config from the compiled CLI:
npm run config -- path
npm run config -- show --scope=merged
npm run config -- device list --scope=merged
npm run config -- device set board-a --host=192.168.10.58 --user=orangepi --password-env=BOARD_A_PASSWORD
npm run config -- defaults set viewerPort auto
npm run launch # Start MCP + SSH + open browser terminal
npm run status # Check server/session status
npm run devices # List configured device profiles
npm run kill # Kill leftover processes
npm run cleanup # Kill + clean state files
npm run logs # View local JSONL metadata logs
# Claude Code
claude mcp add --transport stdio ssh-session-mcp -- node /path/to/build/index.js
# Codex CLI
codex mcp add ssh-session-mcp -- node /path/to/build/index.js
No need to pass SSH credentials on the command line — they are read from .env.
See AI_AGENT_GUIDE.md for the full guide.
ssh-quick-connect → ssh-run → read output → decide → ssh-run → ...
| Tool | Purpose |
|---|---|
ssh-quick-connect | Connect SSH + open browser terminal (once per conversation) |
ssh-device-list | List configured device profiles and defaults |
ssh-run | Execute command, return output with exit code (repeat as needed) |
ssh-status | Check sessions, terminal mode, and operation mode |
ssh-session-set-active | Switch the active session used when session is omitted |
ssh-session-diagnostics | Inspect lock state, viewer state, running command metadata, and trim warnings |
ssh-session-history | Read line-numbered mixed history of output and user/agent actions |
ssh-command-status | Poll async command progress |
ssh-retry | Retry flaky commands with backoff |
AI: ssh-quick-connect()
→ "Connected. Terminal at http://127.0.0.1:8793/terminal/session/..."
AI: ssh-run({ command: "uname -a" })
→ { exitCode: 0, completionReason: "sentinel" }
"Linux board 5.10.160-rockchip-rk3588 aarch64"
AI: ssh-run({ command: "apt update" })
→ { async: true, commandId: "abc123", hint: "Use ssh-command-status to check" }
AI: ssh-command-status({ commandId: "abc123" })
→ { status: "completed", exitCode: 0 }
The browser terminal has a safe/full mode selector (top-right):
| Mode | Behavior |
|---|---|
| safe (default) | Blocks dangerous commands (rm -rf, mkfs), interactive programs (vim, htop), and streaming commands (tail -f). Returns suggestions for alternatives. |
| full | AI has full control. Only blocks extreme threats (fork bombs, dd to disk). Other dangerous commands execute with warnings. |
Switching to Full mode requires confirmation via browser dialog.
Configure via SSH_MCP_MODE=safe|full env var or --mode=safe|full flag.
The browser terminal has a mode selector (top-right dropdown):
| Mode | Who can type |
|---|---|
| common (default) | Both user and AI |
| user | Only user. AI's ssh-run returns INPUT_LOCKED error. |
| claude/codex | Only AI. User keyboard input is blocked. |
The AI automatically acquires/releases the lock when calling ssh-run.
| Tool | Description |
|---|---|
ssh-quick-connect | One-step connect + open terminal. Reuses existing sessions. |
ssh-run | Execute command with intelligent completion detection. Returns exit code. |
ssh-status | List active sessions, terminal mode, and operation mode. |
ssh-command-status | Check status of async long-running commands. |
ssh-retry | Execute command with automatic retry and backoff on failure. |
| Tool | Description |
|---|---|
ssh-session-open | Open session with custom parameters |
ssh-session-send | Send raw input without waiting |
ssh-session-read | Read output with offset-based pagination |
ssh-session-history | Read line-numbered history snapshots |
ssh-session-watch | Long-poll for changes, render dashboard |
ssh-session-control | Send control keys (Ctrl+C, arrows, etc.) |
ssh-session-resize | Resize PTY window |
ssh-session-list | List all sessions |
ssh-device-list | List configured device profiles |
ssh-session-set-active | Set or clear the active session |
ssh-session-close | Close a session |
ssh-viewer-ensure | Open viewer window |
ssh-viewer-list | List viewer processes |
| Variable | Description | Default |
|---|---|---|
SSH_HOST | SSH host address | (required) |
SSH_PORT | SSH port | 22 |
SSH_USER | SSH username | (required) |
SSH_PASSWORD | SSH password | - |
SSH_KEY | Path to SSH private key | - |
SSH_MCP_INSTANCE | Instance id for per-AI runtime isolation | auto (proc-<pid>) |
SSH_MCP_CONFIG | Path to ssh-session-mcp.config.json | auto-discovery |
VIEWER_HOST | Viewer server bind address | 127.0.0.1 |
VIEWER_PORT | Viewer server port (0 = disabled, auto = random free port) | 0 |
AUTO_OPEN_TERMINAL | Auto-open browser on connect | false |
SSH_MCP_MODE | Operation mode: safe or full | safe |
SSH_MCP_USE_MARKER | Enable sentinel completion markers | true |
SSH_MCP_LOG_MODE | Local log mode: off or meta | off |
SSH_MCP_LOG_DIR | Local JSONL log directory | per-instance runtime dir |
All env variables can be overridden with -- flags:
node build/index.js --host=192.168.1.100 --user=username --viewerPort=8793 --mode=full
./ssh-session-mcp.config.json%APPDATA%\\ssh-session-mcp\\config.json$XDG_CONFIG_HOME/ssh-session-mcp/config.json or ~/.config/ssh-session-mcp/config.jsonSSH_MCP_CONFIG=/path/to/config.json or --config=/path/to/config.jsonConfig files support top-level defaults, defaultDevice, and devices. A workspace config replaces matching devices from the global config by id, while top-level defaults are shallow-merged.
Discovery rule:
SSH_MCP_CONFIG or --config.Auth schema rule:
auth.passwordEnv, auth.keyPathauth.password{
"auth": {
"passwordEnv": "BOARD_A_PASSWORD"
}
}
BOARD_A_PASSWORD=orangepi
Reference example: docs/examples/ssh-session-mcp.config.example.json
Structured tool responses may include these extra top-level fields:
| Field | Meaning |
|---|---|
resultStatus | Normalized outcome: success, partial_success, blocked, failure |
summary | Short human/agent readable summary |
failureCategory | Normalized failure type when blocked or failed |
nextAction | Suggested next step |
evidence | Short supporting facts |
Compatibility note:
resultStatus is the cross-tool decision field.status is still used by some tools for lifecycle values such as running or completed.Reference docs:
npm run launch # Start server + connect SSH + open browser
npm run config -- show --scope=merged
npm run status # Check server and session status
npm run devices # List configured device profiles
npm run kill # Kill process on viewer port
npm run cleanup # Kill + remove state files
npm run logs # Inspect local server/session JSONL logs
npm run validate:repo # Validate repo docs/config contract coverage
npm run build # Compile TypeScript
npm run test # Run unit tests
npm run inspect # Open MCP inspector
Useful flags:
node scripts/ctl.mjs launch --instance=codex-a --device=board-a --connection=main
node scripts/ctl.mjs status --instance=codex-a
node scripts/ctl.mjs logs --instance=codex-a --session=board-a/main
Terminal mode
Browser mode
.env only, excluded from git and npm127.0.0.1 by default (local only)SSH_KEY instead of SSH_PASSWORD when possiblenpm run validate:repo: checks required docs, example config validity, acceptance scenario ids, .env.example, and MCP tool coverage in docsThis repository stays focused on the SSH transport/runtime layer: sessions, viewers, targeting, locks, logging, and tool contracts. Project-specific prompts, ROS workflows, board-role logic, model pipelines, and higher-level agent skills should live outside this repo.
This repository is licensed under the Apache License 2.0.
See also NOTICE for project attribution metadata.
FAQs
Persistent SSH PTY session manager for MCP clients with actor-aware input tracking, terminal-style dashboard rendering, and automatic session cleanup.
The npm package ssh-session-mcp receives a total of 38 weekly downloads. As such, ssh-session-mcp popularity was classified as not popular.
We found that ssh-session-mcp demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Product
Socket can now send alerts and supply chain attack notifications to Microsoft Teams, with filters that route the right updates to each channel.

Security News
pnpm 12 rewrites the package manager in Rust, cutting install times by up to 90% while preserving pnpm 11 workflows and lockfiles.

Security News
Socket CTO Ahmad Nassri joins AppSec leaders at Black Hat to discuss active malware, package manager risks, and software supply chain defense.