Skip to main content
Glama
idletoaster

SSH MCP Server

by idletoaster
README.md
# ๐Ÿš€ SSH MCP Server (Node.js)

[![NPM Version](https://img.shields.io/npm/v/@idletoaster/ssh-mcp-server)](https://www.npmjs.com/package/@idletoaster/ssh-mcp-server)
[![GitHub Issues](https://img.shields.io/github/issues/idletoaster/ssh-mcp-server)](https://github.com/idletoaster/ssh-mcp-server/issues)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org/)

A secure, high-performance **Model Context Protocol (MCP) server** that enables AI assistants like Claude Desktop to execute SSH commands on remote servers. Built with Node.js and the official MCP SDK for maximum compatibility and reliability.

> **๐Ÿ”„ Version 2.1.0 - Token-Efficient File Operations**: Complete rewrite in Node.js with official MCP SDK - eliminates all previous Go compatibility issues!

---

## โœจ Features

- ๐Ÿ” **Secure SSH**: Private key authentication with multiple key format support
- ๐Ÿค– **AI-Ready**: Official MCP SDK integration for Claude Desktop and other AI tools
- โšก **High Performance**: Node.js async architecture for fast command execution
- ๐Ÿ“ฆ **Zero Setup**: One-command installation via NPX - no compilation required
- ๐ŸŒ **Universal**: Pure JavaScript runs on Windows, macOS, and Linux
- ๐Ÿ›ก๏ธ **Type Safe**: Built with modern JavaScript and comprehensive error handling
- ๐Ÿ“‹ **Standards Compliant**: Uses official @modelcontextprotocol/sdk

---

## ๐Ÿš€ Quick Start

### Installation & Usage
```bash
# Use directly with NPX (recommended)
npx @idletoaster/ssh-mcp-server@latest

# Or install globally
npm install -g @idletoaster/ssh-mcp-server
```

### Claude Desktop Configuration
Add to your Claude Desktop MCP configuration file:

```json
{
  "mcpServers": {
    "ssh": {
      "command": "npx",
      "args": ["-y", "@idletoaster/ssh-mcp-server@latest"],
      "env": {}
    }
  }
}
```

**That's it!** Claude can now execute SSH commands on your remote servers.

---

## ๐Ÿ’ฌ Usage Examples

Once configured, Claude can help you with commands like:

> **"Check disk usage on my production server at 192.168.1.100"**

> **"Restart the nginx service on server.example.com as user admin"**

> **"Show running processes on my Ubuntu server using my SSH key"**

### Manual Tool Usage
```json
{
  "tool": "remote-ssh",
  "arguments": {
    "host": "192.168.1.100",
    "user": "ubuntu",
    "command": "df -h",
    "privateKeyPath": "/home/user/.ssh/id_rsa"
  }
}
```

---

## ๐Ÿ”ง Configuration

### SSH Key Authentication
The server supports multiple authentication methods:

#### 1. Explicit Key Path
```json
{
  "privateKeyPath": "/path/to/your/private/key"
}
```

#### 2. Environment Variable
```bash
export SSH_PRIVATE_KEY="/home/user/.ssh/id_rsa"
```

#### 3. Auto-Discovery
Automatically searches for keys in:
- `~/.ssh/id_rsa`
- `~/.ssh/id_ed25519` 
- `~/.ssh/id_ecdsa`

### Supported Key Formats
- โœ… RSA keys (`id_rsa`)
- โœ… ED25519 keys (`id_ed25519`)
- โœ… ECDSA keys (`id_ecdsa`)
- โœ… OpenSSH format
- โœ… PEM format

---

## ๐Ÿ› ๏ธ Development

### Prerequisites
- **Node.js 18+** (check: `node --version`)
- **NPM 9+** (check: `npm --version`)

### Install Node.js

#### Windows:
Download from [nodejs.org](https://nodejs.org/) or use Chocolatey:
```bash
choco install nodejs
```

#### Linux (Ubuntu/Debian):
```bash
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
```

#### Linux (CentOS/RHEL):
```bash
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
sudo yum install -y nodejs
```

#### macOS:
```bash
brew install node
```

### Build from Source
```bash
# Clone repository
git clone https://github.com/idletoaster/ssh-mcp-server.git
cd ssh-mcp-server

# Install dependencies
npm install

# Run locally
npm start

# Development with auto-reload
npm run dev
```

---

## ๐Ÿ—๏ธ Architecture

```
ssh-mcp-server/
โ”œโ”€โ”€ package.json          # NPM configuration & dependencies
โ”œโ”€โ”€ index.js              # Main MCP server (Official SDK)
โ”œโ”€โ”€ lib/
โ”‚   โ””โ”€โ”€ ssh-client.js     # SSH connection management
โ”œโ”€โ”€ README.md             # Documentation
โ”œโ”€โ”€ LICENSE               # MIT license
โ””โ”€โ”€ .gitignore           # Node.js gitignore
```

### Technology Stack
- **Runtime**: Node.js 18+ with ES Modules
- **MCP SDK**: @modelcontextprotocol/sdk (Official)
- **SSH**: ssh2 library for Node.js
- **Distribution**: NPM with direct NPX execution

---

## ๐Ÿ”’ Security

### Best Practices
- โœ… Private key authentication only (no passwords)
- โœ… Configurable SSH algorithms and timeouts
- โœ… No persistent connections (session-based)
- โœ… Input validation and sanitization
- โœ… Comprehensive error handling

### Security Guidelines
- ๐Ÿ” Store private keys with restrictive permissions (`chmod 600`)
- ๐ŸŒ Use SSH key passphrases when possible
- ๐Ÿ›ก๏ธ Restrict SSH keys to specific hosts in `~/.ssh/config`
- ๐Ÿ“ Monitor SSH access logs
- ๐Ÿšซ Never run as root unless absolutely necessary

### Network Security
```bash
# Example SSH config for restricted access
Host production-server
    HostName 192.168.1.100
    User deploy
    IdentityFile ~/.ssh/production_key
    IdentitiesOnly yes
    StrictHostKeyChecking yes
```

---

## ๐Ÿงช Testing

### Local Testing
```bash
# Test the MCP server
echo '{"host":"test.server.com","user":"testuser","command":"whoami"}' | npm start
```

### Integration Testing
```bash
# Verify Node.js installation
node --version  # Should be 18+
npm --version   # Should be 9+

# Test NPX execution
npx @idletoaster/ssh-mcp-server@latest --help
```

---

## ๐ŸŒ Compatibility

### Operating Systems
- โœ… **Windows** 10/11 (x64, ARM64)
- โœ… **macOS** 12+ (Intel & Apple Silicon)
- โœ… **Linux** (x64, ARM64) - All major distributions

### AI Platforms
- ๐Ÿค– **Claude Desktop** (Primary target)
- ๐Ÿค– **Cursor IDE** 
- ๐Ÿค– **Any MCP-compatible application**

### Node.js Compatibility
- โœ… **Node.js 18.x** (LTS)
- โœ… **Node.js 20.x** (LTS) 
- โœ… **Node.js 22.x** (Current)

---

## ๐Ÿ“Š Migration from v1.x (Go)

**Upgrading from the Go version?** The Node.js version offers:

### โœ… Improvements
- **Zero compilation** - No more binary builds
- **Better compatibility** - Official MCP SDK
- **Faster development** - Direct code changes
- **Simpler deployment** - Pure NPX distribution
- **No protocol issues** - Official Anthropic SDK

### ๐Ÿ”„ Migration Steps
1. **Uninstall old version**: Remove Go-based installation
2. **Install new version**: `npx @idletoaster/ssh-mcp-server@latest`
3. **Update Claude config**: Same configuration works!
4. **Test connection**: Verify SSH functionality

---

## ๐Ÿค Contributing

### Development Workflow
1. Fork the repository
2. Create a feature branch: `git checkout -b feature/amazing-feature`
3. Make your changes
4. Test thoroughly: `npm test`
5. Submit a pull request

### Code Style
- Use ES6+ modern JavaScript
- Follow Node.js best practices
- Add JSDoc comments for functions
- Validate with existing patterns

---

## ๐Ÿ“„ License

MIT License - see [LICENSE](LICENSE) file for details.

---

## ๐Ÿ™ Acknowledgments

- **[@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/sdk)** - Official MCP SDK
- **[ssh2](https://github.com/mscdex/ssh2)** - Node.js SSH client
- **[Claude Desktop](https://claude.ai)** - Primary target platform
- **[Model Context Protocol](https://modelcontextprotocol.io)** - Standard specification

---

## ๐Ÿ“ž Support

- ๐Ÿ“‹ **Issues**: [GitHub Issues](https://github.com/idletoaster/ssh-mcp-server/issues)
- ๐Ÿ’ฌ **Discussions**: [GitHub Discussions](https://github.com/idletoaster/ssh-mcp-server/discussions)


---

*Built with โค๏ธ for the AI development community using Node.js and official MCP SDK*

## ๐Ÿ†• NEW in v2.1.0: Token-Efficient File Operations

Enhanced with 4 powerful tools inspired by Desktop Commander for optimal token usage:

### ๐ŸŽฏ Token-Efficient Tools

1. **ssh-edit-block** - Edit specific text blocks (80-90% token reduction vs full rewrites)
2. **ssh-read-lines** - Read file sections by line numbers (massive savings for large files)  
3. **ssh-search-code** - Pattern search without reading full files
4. **ssh-write-chunk** - Efficient content writing with append/rewrite modes

### ๐Ÿ’ก Benefits

- **80-90% fewer tokens** for file operations
- **No more full file rewrites** for small changes
- **Partial file reading** for large codebases
- **Pattern searching** without token overhead

### ๐Ÿ“– New Tool Usage

```javascript
// Edit specific text blocks
{
  "name": "ssh-edit-block",
  "arguments": {
    "host": "server.com",
    "user": "username", 
    "filePath": "/path/to/file.js",
    "oldText": "version: '2.0.0'",
    "newText": "version: '2.1.0'"
  }
}

// Read specific lines only
{
  "name": "ssh-read-lines", 
  "arguments": {
    "host": "server.com",
    "user": "username",
    "filePath": "/path/to/large-file.js",
    "startLine": 100,
    "endLine": 150
  }
}

// Search patterns efficiently
{
  "name": "ssh-search-code",
  "arguments": {
    "host": "server.com", 
    "user": "username",
    "path": "/project",
    "pattern": "function.*export",
    "filePattern": "*.js"
  }
}
```

TDQS

A3.7/5.0

Scored across 5 tools

Disambiguation5/5

Each tool has a clearly distinct purpose: remote-ssh for general command execution, and the four ssh-* tools for specific file operations (edit block, read lines, search code, write chunk). There is no overlap or ambiguity.

Naming Consistency4/5

Four tools follow the consistent 'ssh-verb-noun' pattern (e.g., ssh-read-lines), but 'remote-ssh' breaks this pattern. Still, the naming is mostly consistent and predictable.

Tool Count5/5

With 5 tools, the server is well-scoped for its purpose of SSH remote operations. It covers essential file manipulation and command execution without being too sparse or bloated.

Completeness4/5

The tool set covers command execution and core file operations (read, write, edit, search). However, it lacks file listing, deletion, or transfer capabilities, leaving minor gaps for a complete SSH toolkit.

Maintenance

ActivityInactive
ResponsivenessNo issues