Skip to main content
Glama

ssh-mcp-server

SSH access for AI agents through the Model Context Protocol

npm license node

Installation · Configuration · Tools · Security


An MCP server that lets AI agents connect to remote hosts over SSH. Run commands, manage files, control services and containers, and monitor server health through a persistent connection.

Features

  • Persistent sessions: connect once, run many commands without reconnecting

  • State preservation: shell environment and working directory persist between calls

  • Policy enforcement: commands are classified by risk, destructive operations require confirmation

  • Audit logging: operations logged to stderr as JSON

Related MCP server: mcp-ssh-terminal

Installation

npx @regele/ssh-mcp-server

Or install globally:

npm install -g @regele/ssh-mcp-server
ssh-mcp-server

From source

Requires Bun for building.

git clone https://github.com/k6w/ssh-mcp-server.git
cd ssh-mcp-server
bun install
bun run build
node dist/index.js

Configuration

Claude Code

claude mcp add ssh -- npx @regele/ssh-mcp-server

Or with a local build:

claude mcp add ssh -- node /path/to/ssh-mcp-server/dist/index.js

MCP config file

{
  "mcpServers": {
    "ssh": {
      "command": "npx",
      "args": ["@regele/ssh-mcp-server"]
    }
  }
}

SSH agent

Without a password or key, the server uses your SSH agent (SSH_AUTH_SOCK or Pageant on Windows). Pass the socket explicitly if needed:

{
  "mcpServers": {
    "ssh": {
      "command": "npx",
      "args": ["@regele/ssh-mcp-server"],
      "env": { "SSH_AUTH_SOCK": "/path/to/agent.sock" }
    }
  }
}

Architecture

flowchart LR
    subgraph Client
        A[MCP Client]
    end

    subgraph Server[ssh-mcp-server]
        direction TB
        T[Tools]
        T --> P[policy.ts]
        T --> AU[audit.ts]
        T --> V[validation.ts]
        T --> SM[session-manager.ts]
        SM --> SS[shell-session.ts]
        SM --> JM[job-manager.ts]
        SM --> SF[sftp-manager.ts]
    end

    subgraph Remote
        H[Remote Hosts]
    end

    A <-->|stdio| T
    SM <-->|SSH| H

Tools

32 tools across 7 categories.

Connection

Tool

Description

ssh_connect

Open session with password, key, or agent auth

ssh_disconnect

Close session

ssh_list_sessions

List active sessions

Execution

Tool

Description

ssh_exec

Run command, return stdout/stderr/exitCode

ssh_shell_start

Open interactive PTY shell

ssh_shell_send

Send input to shell

ssh_shell_read

Read shell output

ssh_shell_close

Close shell

Background Jobs

Tool

Description

ssh_job_start

Start long-running command

ssh_job_status

Check job state

ssh_job_output

Read job output

ssh_job_kill

Kill running job

ssh_job_list

List jobs

Files (SFTP)

Tool

Description

ssh_file_read

Read file contents

ssh_file_write

Write file with auto-backup

ssh_file_list

List directory

ssh_file_stat

Get file metadata

ssh_file_delete

Delete file

ssh_mkdir

Create directory

Status

Tool

Description

ssh_server_status

System snapshot: OS, load, memory, disk, services, containers

Services (systemd)

Tool

Risk

Description

ssh_service_status

safe

Show unit state

ssh_service_start

mutating

Start unit

ssh_service_restart

mutating

Restart with verification

ssh_service_stop

dangerous

Stop unit (requires allowDangerous)

ssh_service_logs

safe

Read journal entries

Docker

Tool

Risk

Description

ssh_docker_ps

safe

List containers

ssh_docker_logs

safe

Container logs

ssh_docker_start

mutating

Start container

ssh_docker_restart

mutating

Restart container

ssh_docker_stop

dangerous

Stop container (requires allowDangerous)

ssh_docker_compose_up

mutating

Start compose stack

ssh_docker_compose_down

dangerous

Stop compose stack (requires allowDangerous)

Security

Risk tiers

Commands are classified before execution:

Tier

Behavior

Examples

safe

Runs

ls, cat, docker ps, systemctl status

mutating

Runs

mv, cp, docker start, systemctl restart

dangerous

Requires allowDangerous: true

rm -rf, kill -9, docker stop

blocked

Always refused

shutdown, reboot, rm -rf /, mkfs

Policy coverage

Tools

Policy

Audit

ssh_service_*, ssh_docker_*

Yes

Yes

ssh_server_status

Yes

No

ssh_exec, ssh_shell_*, ssh_job_*

No

No

ssh_file_*

No

No

NOTE

ssh_exec and shell tools pass commands directly. Use a restricted account.

Audit format

{"timestamp":"...","sessionId":"...","command":"systemctl restart nginx","tier":"mutating","allowed":true,"exitCode":0,"durationMs":412}

Limitations

  • No host key verification: accepts any server key

  • Credentials in memory: passwords/keys kept for session lifetime

  • Timeouts do not cancel remote commands: use jobs for long work

  • Sessions lost on restart

Recommendations

  1. Use a dedicated non-root account with limited sudo

  2. Enable confirmation prompts in your MCP client

  3. Prefer key authentication with passphrase

  4. Keep allowDangerous off unless necessary

  5. Review audit logs after agent sessions

Development

bun install          # install dependencies
bun run build        # bundle to dist/index.js
bun run typecheck    # type-check with tsc
bun run start        # run server

License

MIT

Tool Schema Changelog

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

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to have persistent, fully interactive SSH sessions into remote hosts, behaving like a local terminal.
      19 npm
      2
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to securely execute commands on remote hosts via SSH and SFTP, with persistent shells, file transfers, screenshots, and an audit log.
      5
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to manage remote servers via SSH, including command execution, multi-host batch operations, SFTP file transfer, background job handling, DevOps diagnostics, port tunneling, and safety guardrails like high-risk command blocking and read-only mode.
      MIT