Content
# sshcode-mcp
SSH Remote AI Development Tool — Enables AI to perform development operations on a remote computer via SSH.
Based on the [MCP (Model Context Protocol)](https://modelcontextprotocol.io) standard protocol, can be used as a tool service for MCP clients like opencode, Claude Desktop.
## Features
| Tool | Description |
|------|-------------|
| `execute_command` | Execute shell command on remote server |
| `read_file` | Read remote file content |
| `write_file` | Write/overwrite remote file |
| `edit_file` | Edit remote file at specified line (by line number) |
| `list_directory` | List remote directory content |
| `create_directory` | Create remote directory |
| `delete_path` | Delete remote file/directory |
| `rename_path` | Rename/move remote file/directory |
| `file_stat` | Get remote file metadata |
| `search_files` | Search files on remote server (glob pattern) |
| `get_system_info` | Get remote system information |
| `get_pool_stats` | Get connection pool/cache statistics |
## Quick Start
```bash
# Install dependencies
npm install
# Password authentication
node bin/sshcode.js ubuntu@192.168.1.5 -P 123
# Key authentication
node bin/sshcode.js ubuntu@192.168.1.5 -i ~/.ssh/id_rsa
# Custom port
node bin/sshcode.js ubuntu@192.168.1.5 -p 2222 -P 123
```
### Environment Variable Mode (MCP Recommended)
```bash
export SSHCODE_HOST=192.168.1.5
export SSHCODE_USER=ubuntu
export SSHCODE_PASSWORD=123
node bin/sshcode.js
```
## Configure as opencode MCP Service
Add the following configuration to `~/.config/opencode/opencode.jsonc` or project `.opencode.jsonc`:
```jsonc
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"sshcode": {
"type": "local",
"command": ["node", "/path/to/sshcode_mcp/bin/sshcode.js"],
"environment": {
"SSHCODE_HOST": "192.168.1.5",
"SSHCODE_USER": "ubuntu",
"SSHCODE_PASSWORD": "123",
"SSHCODE_PORT": "22"
},
"timeout": 15000
}
}
}
```
## Architecture
```
AI (MCP Client) <-> stdio JSON-RPC <-> sshcode-mcp <-> SSH <-> Remote Server
```
## Performance Optimization
- **Connection Pool**: Reuse SSH connections (up to 5), avoid repeated handshakes
- **File Cache**: LRU cache (up to 50 files, TTL 60s)
- **Command Timeout**: Default 30s, prevent long-time blocking
- **Concurrency Control**: Up to 10 concurrent commands
- **Output Truncation**: Automatically truncate output exceeding 10MB
- **SFTP Reuse**: Reuse SFTP channel within the same connection
- **SSH Compression**: Force enable compression to reduce bandwidth
## Configuration
```bash
# View configuration
node bin/sshcode.js config
# Modify configuration
node bin/sshcode.js config set pool.maxSize 10
node bin/sshcode.js config set command.defaultTimeout 60000
```
## License
MIT