
An MCP tool to manage persistent ssh connections to a collection of hosts enabling remote development, deployment, and information gathering.
概览
A Model Context Protocol (MCP) server that gives LLM clients safe, persistent SSH access to remote machines. ssh-mcp lets MCP-compatible clients (such as Claude Code, Cursor, or custom MCP inspectors) control remote machines through SSH. Once hosts are registered, the server maintains persistent shell sessions that retain environment state between commands—ideal for multi-step workflows, long-running processes, or interactive diagnostics. The server is implemented in TypeScript on top of the official @modelcontextprotocol/sdk. - exposes functionality through standard MCP tool definitions. - keep shell sessions alive, preserving working directory, environment variables, and process state across multiple commands. - manage SSH targets through durable JSON configuration (~/.ssh-mcp/hosts.json). - supports passwords, private keys, and SSH agent forwarding (fallback). - sessions auto-close after prolonged inactivity; commands are marked and monitored for completion.
README
以下为原文 README 节选,完整内容请查看原文。
SSH MCP Server
A Model Context Protocol (MCP) server that gives LLM clients safe, persistent SSH access to remote machines.
Table of Contents
- Overview
- Key Features
- Architecture
- Installation
- Running the Server
- Client Integrations
- Host Configuration
- Session Management
- Authentication Modes
- Timeouts & Inactivity Handling
- Directory Structure
- Using the MCP Tools
- Testing
- Troubleshooting
- Security Considerations
- Contributing
- License
Overview
ssh-mcp lets MCP-compatible clients (such as Claude Code, Cursor, or custom MCP inspectors) control remote machines through SSH. Once hosts are registered, the server maintains persistent shell sessions that retain environment state between commands—ideal for multi-step workflows, long-running processes, or interactive diagnostics.
The server is implemented in TypeScript on top of the official @modelcontextprotocol/sdk.
Key Features
- MCP-compliant: exposes functionality through standard MCP tool definitions.
- Persistent sessions: keep shell sessions alive, preserving working directory, environment variables, and process state across multiple commands.
- Stored host profiles: manage SSH targets through durable JSON configuration (
~/.ssh-mcp/hosts.json). - Flexible authentication: supports passwords, private keys, and SSH agent forwarding (fallback).
- Timeout & cleanup safeguards: sessions auto-close after prolonged inactivity; commands are marked and monitored for completion.
- Structured listings: query active sessions and saved hosts directly from the MCP client.
Architecture
MCP Client ─┬─> add-host / edit-host / remove-host
│
├─> list-hosts
│
├─> start-session ─┬─> PersistentSession (ssh2 shell)
│ ├─> exec (reuses shell, captures stdout/stderr)
│ └─> close-session / auto-timeout
│
└─> list-sessions
Persistent configuration → ~/.ssh-mcp/hosts.json
安装
npx ssh-mcp-sessions配置
{
"mcpServers": {
"ssh-mcp": {
"command": "npx",
"args": [
"ssh-mcp-sessions"
]
}
}
}