SSH MCP Server

SSH MCP Server

Enables SSH connections and remote command execution with persistent session management and real-time browser-based terminal monitoring. Supports multiple simultaneous SSH sessions with command history tracking and live WebSocket streaming of terminal output.

Category
访问服务器

README

SSH MCP Server

A Model Context Protocol (MCP) server that provides SSH session management for Claude Code with browser-based terminal monitoring.

Features

  • Persistent SSH Sessions - Named SSH connections that maintain state across commands
  • Real-time Terminal Monitoring - Browser interface with live terminal output via WebSocket
  • Multi-Session Support - Manage multiple independent SSH sessions simultaneously
  • Command History - Track executed commands with timestamps and exit codes
  • Session Isolation - Each session maintains separate terminal history and state

Installation & Setup

Prerequisites

  • Node.js 16+ and npm
  • Claude Code CLI installed and configured
  • SSH server access (for remote connections)
  • TypeScript (for development)

1. Clone and Build

git clone <repository-url> ls-ssh-mcp
cd ls-ssh-mcp
npm install
npm run build

2. Register with Claude Code

# Use the installation script (recommended)
./install-mcp.sh

# Or manually register
claude mcp add ssh node /absolute/path/to/ls-ssh-mcp/dist/src/mcp-server.js

3. Verify Installation

# Check that the server was registered
claude mcp list

How it works:

  • The install-mcp.sh script registers the server with Claude Code with an auto-discovered port
  • Claude Code automatically starts the server when you use SSH tools
  • No need to manually start/stop - the server runs on-demand
  • Web monitoring interface is available at http://localhost:{port}/session/{session-name}

The installation script handles port discovery, cleanup of existing configurations, and proper registration.

Usage

Basic Workflow

  1. Connect to SSH server: Use ssh_connect with your credentials
  2. Execute commands: Use ssh_exec to run commands on the remote server
  3. Monitor sessions: Use ssh_get_monitoring_url to get browser monitoring URL
  4. Manage sessions: Use ssh_list_sessions and ssh_disconnect as needed

Available MCP Tools

Tool Purpose Required Parameters
ssh_connect Establish SSH connection name, host, username, auth method*
ssh_exec Execute commands on remote server sessionName, command
ssh_list_sessions List all active SSH sessions None
ssh_get_monitoring_url Get browser monitoring URL sessionName
ssh_disconnect Disconnect an SSH session sessionName

* Authentication methods: Choose one:

  • password - SSH user account password
  • privateKey - Direct private key content (+ optional passphrase if key is encrypted)
  • keyFilePath - Path to private key file (+ optional passphrase if key is encrypted)

Example Usage

# 1. Connect to a server (multiple authentication methods)

# Option A: Username/password authentication
ssh_connect name="myserver" host="example.com" username="user" password="pass"

# Option B: SSH key file (recommended)
ssh_connect name="myserver" host="example.com" username="user" keyFilePath="~/.ssh/id_rsa"

# Option C: SSH key file with passphrase (encrypted key)
ssh_connect name="myserver" host="example.com" username="user" keyFilePath="~/.ssh/id_ed25519" passphrase="mypassphrase"

# Option D: Direct private key content (unencrypted)
ssh_connect name="myserver" host="example.com" username="user" privateKey="-----BEGIN OPENSSH PRIVATE KEY-----..."

# Option E: Direct private key content (encrypted with passphrase)
ssh_connect name="myserver" host="example.com" username="user" privateKey="-----BEGIN OPENSSH PRIVATE KEY-----..." passphrase="keypassword"

# 2. Execute commands
ssh_exec sessionName="myserver" command="ls -la"
ssh_exec sessionName="myserver" command="htop"

# 3. Get monitoring URL for real-time terminal
ssh_get_monitoring_url sessionName="myserver"
# Returns: http://localhost:8082/session/myserver

# 4. List all active sessions
ssh_list_sessions

# 5. Disconnect when done
ssh_disconnect sessionName="myserver"

Web Monitoring Interface

The browser interface provides:

  • Live terminal output via WebSocket connection
  • Command history with timestamps and exit codes
  • Real-time streaming of command execution
  • Session-specific URLs for each SSH connection

SSH Authentication Methods

The server supports multiple SSH authentication methods with automatic fallback:

1. SSH Key Files (Recommended)

  • Best for: Regular usage, automated deployments, security-conscious users
  • Supports: RSA, ED25519, ECDSA key formats
  • Encryption: Both encrypted (with passphrase) and unencrypted keys
  • Path expansion: Supports tilde expansion (~/.ssh/id_rsa)
# Unencrypted key
ssh_connect name="prod" host="server.com" username="deploy" keyFilePath="~/.ssh/id_ed25519"

# Encrypted key with passphrase
ssh_connect name="secure" host="server.com" username="admin" keyFilePath="~/.ssh/id_rsa" passphrase="mysecretpass"

2. Username/Password

  • Best for: Quick testing, one-off connections, legacy systems
  • Security note: Less secure than key-based authentication
ssh_connect name="test" host="server.com" username="user" password="password"

3. Direct Private Key Content (Legacy)

  • Best for: Programmatic usage, CI/CD systems with key management
  • Note: Requires pasting full private key content
ssh_connect name="ci" host="server.com" username="deploy" privateKey="-----BEGIN OPENSSH PRIVATE KEY-----..."

Authentication Priority

  1. privateKey (if provided) - highest priority
  2. keyFilePath (if provided) - recommended method
  3. password (if provided) - fallback method

Configuration

Environment Variables

  • SSH_TIMEOUT - SSH operation timeout in milliseconds (default: 30000)
  • MAX_SESSIONS - Maximum concurrent SSH sessions (default: 10)
  • LOG_LEVEL - Logging level: 'error', 'warn', 'info', 'debug' (default: 'info')

Web server port is automatically discovered and managed by the installation script.

Development

Setup Development Environment

# Install dependencies
npm install

# Run in development mode with auto-reload
npm run dev

# Run tests
npm test

# Run E2E tests (requires SSH server on localhost)
npm run test:e2e

# Build for production
npm run build

# Lint code
npm run lint

Testing Requirements

For running tests, you need:

  • SSH server running on localhost
  • Test user account: test_user with password password123
  • Or configure your own test credentials in the test files

Project Structure

├── src/
│   ├── mcp-server.ts              # Main server orchestrator
│   ├── mcp-ssh-server.ts          # MCP protocol handler
│   ├── web-server-manager.ts      # Web interface server
│   ├── ssh-connection-manager.ts  # SSH session management
│   └── types.ts                   # TypeScript definitions
├── static/                        # xterm.js terminal interface
├── install-mcp.sh                 # Installation script
└── dist/                          # Compiled output

Security Considerations

  • SSH sessions are kept in memory only
  • Credentials are not persisted
  • Web interface runs on localhost by default
  • Use SSH key authentication when possible

Architecture

The server runs two components in the same process:

  • MCP Server: Communicates with Claude Code via stdio protocol (no network port)
  • Web Server: Provides browser interface via HTTP and WebSocket on auto-discovered port

Port Management

  • MCP communication: Uses stdio transport only (stdin/stdout with Claude Code)
  • Web interface: Single auto-discovered port serves both HTTP routes and WebSocket connections
  • Port discovery: Installation script discovers available port and stores as WEB_PORT environment variable for the MCP server process
  • Coordination: Shared SSH session manager enables MCP tools to return monitoring URLs pointing to the web interface

Deployment Modes

  • Production: Claude Code automatically starts mcp-server.js on-demand when SSH tools are used
  • Development: Manual testing via orchestrator.js with independent port discovery

Sessions are shared between both components for unified SSH management.

Troubleshooting

Common Issues

Server not starting after registration:

# Check if Claude Code recognizes the server
claude mcp list

# Verify build exists
ls -la dist/src/mcp-server.js

# Test the server directly
node dist/src/mcp-server.js

Port conflicts:

# Re-run installation to discover new port
./install-mcp.sh

# Verify new configuration
claude mcp get ssh

SSH connection failures:

  • Verify SSH server is running and accessible
  • Check credentials (username/password or privateKey)
  • Ensure SSH server allows password authentication if using passwords

Web interface not accessible:

  • Use ssh_get_monitoring_url to get the correct URL with current port
  • Check that the server is running: ps aux | grep mcp-server

Logs and Debugging

# Enable debug logging when using Claude Code
export LOG_LEVEL=debug

# Check MCP server configuration
claude mcp get ssh

# Test server manually with debug output
LOG_LEVEL=debug node dist/src/mcp-server.js

License

MIT License - see LICENSE file for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选