SSH MCP Server

SSH MCP Server

Enables AI assistants to execute SSH commands and perform token-efficient file operations on remote servers via the Model Context Protocol.

Category
访问服务器

README

🚀 SSH MCP Server (Node.js)

NPM Version GitHub Issues License: MIT Node.js

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

# 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:

{
  "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

{
  "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

{
  "privateKeyPath": "/path/to/your/private/key"
}

2. Environment Variable

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 or use Chocolatey:

choco install nodejs

Linux (Ubuntu/Debian):

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

Linux (CentOS/RHEL):

curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
sudo yum install -y nodejs

macOS:

brew install node

Build from Source

# 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

# 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

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

Integration Testing

# 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 file for details.


🙏 Acknowledgments


📞 Support


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

// 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"
  }
}

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选