mcp-ssh-server
Bridges VS Code on Windows with remote Linux servers via SSH, enabling AI assistants to interact with remote development environments.
README
MCP SSH Server
A Model Context Protocol (MCP) server that bridges VS Code on Windows with remote Linux servers via SSH. This enables AI assistants like GitHub Copilot to seamlessly interact with remote development environments.
Features
- 🔐 Password-to-Key Bootstrap: Connect once with a password, then automatically use SSH keys for all future connections
- 📁 Remote File System Access: Expose remote directories through MCP Resources
- 🛠️ Remote Command Execution: Run shell commands on remote servers with full stdout/stderr capture
- 📝 Direct File Operations: Read and write files directly to remote servers via SFTP
- 🔄 Connection Management: Automatic reconnection and connection pooling
- 🔑 Secure Key Storage: ED25519 keys stored locally in
~/.mcp-ssh/
Architecture
┌─────────────────────┐
│ VS Code + Copilot │
└──────────┬──────────┘
│ stdio (MCP Protocol)
▼
┌─────────────────────┐
│ MCP SSH Server │
│ ┌───────────────┐ │
│ │ Resource │ │ Exposes remote file system
│ │ Handler │ │
│ └───────────────┘ │
│ ┌───────────────┐ │
│ │ Tool Handler │ │ Provides remote operations
│ └───────────────┘ │
│ ┌───────────────┐ │
│ │ SSH Manager │ │ Password-to-key bootstrap
│ └───────────────┘ │
│ ┌───────────────┐ │
│ │ SFTP Client │ │ File operations
│ └───────────────┘ │
└──────────┬──────────┘
│ SSH/SFTP
▼
┌─────────────────────┐
│ Remote Linux │
│ Server │
└─────────────────────┘
Installation
-
Clone the repository:
git clone <repository-url> mcp-ssh-server cd mcp-ssh-server -
Install dependencies:
npm install -
Configure VS Code MCP Settings:
Add this configurationto to your MCP settings file. The location depends on your VS Code configuration:
{ "mcpServers": { "ssh-server": { "command": "node", "args": ["path\\mcp-ssh-server\\src\\index.js"], "env": { "LOG_LEVEL": "info" } } } }
Password-to-Key Bootstrap Flow
The MCP SSH Server implements an intelligent authentication flow:
First Connection
- User provides SSH password
- Server connects using password authentication
- Server automatically generates an ED25519 key pair
- Public key is deployed to
~/.ssh/authorized_keyson the remote server - Private key is stored in
~/.mcp-ssh/keys/id_ed25519_<host> - Connection is re-established using the new key
Subsequent Connections
- Server detects existing key for the host
- Connects directly using key-based authentication
- No password required!
Security Notes
- Keys are stored with
0600permissions (owner read/write only) - Each host gets a unique key pair
- Keys are never transmitted after initial deployment
- Password is only used once and not stored
Available Tools
The MCP server provides the following tools that can be invoked by AI assistants:
1. connect_ssh
Connect to a remote SSH server.
Parameters:
host(required): Remote host address or IPusername(required): SSH usernamepassword(optional): SSH password (only needed for first connection)port(optional): SSH port (default: 22)
Example:
{
"host": "example.com",
"username": "developer",
"password": "initial-password",
"port": 22
}
2. execute_command
Execute a shell command on the remote server.
Parameters:
command(required): Shell command to executeworkingDirectory(optional): Working directory for the command
Example:
{
"command": "gcc main.c -o main && ./main",
"workingDirectory": "/home/developer/project"
}
3. read_file
Read contents of a file from the remote server.
Parameters:
path(required): Absolute or relative path to the file
Example:
{
"path": "/home/developer/config.json"
}
4. write_file
Write content to a file on the remote server.
Parameters:
path(required): Absolute or relative path to the filecontent(required): Content to write
Example:
{
"path": "/home/developer/script.sh",
"content": "#!/bin/bash\necho 'Hello World'"
}
5. list_directory
List contents of a directory on the remote server.
Parameters:
path(optional): Directory path (defaults to home directory)
Example:
{
"path": "/home/developer/projects"
}
VS Code Integration
Using with GitHub Copilot Chat
Once configured, you can interact with your remote server through Copilot:
Example prompts:
- "Connect to my server at dev.example.com as user john"
- "List files in the /var/www directory"
- "Read the nginx configuration file"
- "Compile and run the C++ program in ~/projects/app"
- "Write this code to ~/app/server.js on the remote server"
Chat Variables (Future Enhancement)
To create a custom chat variable like @ssh-server, you would need to:
- Create a VS Code extension that registers the chat participant
- Use the MCP client library to communicate with this server
- Register slash commands like
/connect,/exec,/read,/write
Example extension.js (conceptual):
vscode.chat.createChatParticipant(
"ssh-server",
async (request, context, stream, token) => {
// Connect to MCP server via stdio
// Forward user's request to appropriate tool
// Stream response back to chat
}
);
Configuration
Environment Variables
LOG_LEVEL: Set logging level (debug,info,warn,error) - default:infoLOG_TO_FILE: Enable file logging - default:false
Directory Structure
~/.mcp-ssh/
├── keys/ # SSH private keys
│ ├── id_ed25519_user@host_22
│ └── id_ed25519_user@other_22
├── config/ # Configuration files (future)
└── logs/ # Log files (if enabled)
Usage Examples
Example 1: Connect and Compile Code
User: "Connect to dev.example.com as developer with password 'mypass'"
AI: Uses connect_ssh tool
Server: Connects, generates keys, deploys public key
AI: "Connected! Future connections will use keys."
User: "Compile the C program in ~/project"
AI: Uses execute_command tool
Server: Executes "cd ~/project && gcc main.c -o main"
AI: Returns stdout/stderr and exit code
Example 2: Edit Remote Configuration
User: "Read the nginx config"
AI: Uses read_file tool with path "/etc/nginx/nginx.conf"
Server: Returns file contents
AI: Displays configuration
User: "Add this server block to the config..."
AI: Uses write_file tool
Server: Writes updated configuration
AI: "Configuration updated successfully"
Troubleshooting
Connection Issues
Problem: "Connection timeout"
- Check firewall rules on both Windows and Linux
- Verify SSH service is running:
systemctl status sshd - Test connection manually:
ssh user@host
Problem: "Key authentication failed"
- Check
~/.ssh/authorized_keyspermissions on remote server (should be 600) - Verify
~/.sshdirectory permissions (should be 700) - Check server logs:
sudo tail -f /var/log/auth.log
Key Bootstrap Issues
Problem: "Failed to deploy public key"
- Ensure user has write access to
~/.ssh/authorized_keys - Check if
~/.sshdirectory exists on remote server - Verify password authentication is enabled in
/etc/ssh/sshd_config
File Operation Issues
Problem: "Failed to write file"
- Check file path permissions
- Verify user has write access to the directory
- Ensure parent directories exist
Development
Project Structure
mcp-ssh-server/
├── src/
│ ├── index.js # Entry point
│ ├── config.js # Configuration
│ ├── mcp/
│ │ ├── MCPServer.js # Main MCP server
│ │ ├── ResourceHandler.js # MCP Resources implementation
│ │ └── ToolHandler.js # MCP Tools implementation
│ ├── ssh/
│ │ ├── SSHConnectionManager.js # SSH connection management
│ │ └── KeyManager.js # Key generation and deployment
│ ├── sftp/
│ │ └── SFTPClient.js # SFTP operations wrapper
│ └── utils/
│ └── logger.js # Logging utility
├── package.json
└── README.md
Running in Development Mode
npm run dev
This starts the server with Node.js inspector enabled for debugging.
Security Considerations
- Key Storage: Private keys are stored in
~/.mcp-ssh/keys/with restrictive permissions - Password Handling: Passwords are only used once and never stored
- Connection Security: Uses modern SSH algorithms (ED25519, Curve25519)
- File Operations: All file writes are atomic to prevent corruption
- Logging: Passwords are redacted from logs
License
MIT
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
Acknowledgments
- Built with the Model Context Protocol SDK
- Uses ssh2 for SSH connectivity
- Uses ssh2-sftp-client for SFTP operations
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。