MCP server for SSH remote command execution and file operations
Project description
SSH MCP Server
An MCP (Model Context Protocol) server that enables LLMs to interact with remote servers via SSH functionality including command execution, file upload/download, and directory listing.
Features
- Connection Management: Establish and manage multiple SSH sessions
- Command Execution: Run shell commands on remote servers with full output capture
- File Operations: Upload and download files via SFTP with optional permissions
- Directory Listing: Browse remote directories with file metadata (size, type, timestamps)
- Security: Command injection prevention, proper credential handling, Pydantic validation
- Flexible Authentication: Support for both password and SSH key authentication
Installation
pip install ssh-mcp
Or install from source:
pip install -e .
Requirements
- Python 3.10 or higher
- Dependencies automatically installed via pip
mcp >= 1.0.0pydantic >= 2.0.0paramiko >= 3.0.0
Usage
Running the Server
ssh-mcp
Or using Python directly:
python -m ssh_mcp
Testing with MCP Inspector
The MCP Inspector allows you to test the server interactively:
npx @modelcontextprotocol/inspector python -m ssh_mcp
Available Tools
| Tool | Description |
|---|---|
ssh_connect |
Establish SSH connection to remote server |
ssh_status |
Check status of SSH sessions |
ssh_execute |
Execute commands on remote server |
ssh_upload_file |
Upload files to remote server |
ssh_download_file |
Download files from remote server |
ssh_list_files |
List files in remote directory |
ssh_disconnect |
Close SSH connection |
Example Workflow
1. Connect to a server
Using password authentication:
{
"host": "192.168.1.100",
"port": 22,
"username": "admin",
"password": "your_password"
}
Using SSH key authentication:
{
"host": "192.168.1.100",
"port": 22,
"username": "admin",
"private_key_path": "/home/user/.ssh/id_rsa",
"private_key_password": "key_passphrase" # optional for encrypted keys
}
2. Execute a command
{
"session_id": "admin@192.168.1.100:22",
"command": "ls -la /var/log",
"working_directory": "/var/log", # optional
"response_format": "markdown" // "json" for machine-readable output
}
3. Upload a file
{
"session_id": "admin@192.168.1.100:22",
"local_path": "./config.json",
"remote_path": "/tmp/config.json",
"file_mode": 511 // 0o644 in octal
}
4. Download a file
{
"session_id": "admin@192.168.1.100:22",
"remote_path": "/var/log/syslog",
"local_path": "./syslog",
"overwrite": false
}
5. List a directory
{
"session_id": "admin@192.168.1.100:22",
"remote_path": "/tmp",
"show_hidden": false,
"response_format": "markdown"
}
6. Disconnect
{
"session_id": "admin@192.168.1.100:22"
}
Configuration
Session Management
Multiple concurrent SSH sessions are supported. Each session is identified by a session_id:
- Auto-generated as
{username}@{host}:{port}if not specified - Can be explicitly provided for custom naming
- Sessions persist as long as the server is running
Authentication Methods
The server supports two authentication methods:
-
Password authentication:
- Provide
passwordparameter inssh_connect - Suitable for quick testing or environments where keys are not available
- Provide
-
SSH Key authentication (recommended for production):
- Provide
private_key_pathparameter pointing to your private key file - Optionally provide
private_key_passwordfor encrypted keys - More secure than password-based authentication
- Provide
Response Formats
Tools that return structured data support two formats:
- markdown (default): Human-readable output with formatting
- json: Machine-readable structured data
Development
Setting up the development environment
# Clone the repository
git clone https://github.com/ifindv/ssh-mcp.git
cd ssh-mcp
# Install in development mode
pip install -e ".[dev]"
# Run tests (when available)
pytest
# Format code
black ssh_mcp/
# Type checking
mypy ssh_mcp/
Code Style
This project uses:
- Black for code formatting (line length: 100)
- MyPy for static type checking
- PEP 8 for style guidelines
Security Considerations
- Command injection prevention: Invalid characters are filtered from command inputs
- Host key verification: Uses
AutoAddPolicyby default. For production environments, configure proper host key verification - Credential handling: Credentials are passed via parameters and are not stored persistently
- Input validation: All inputs are validated using Pydantic models
- Sensitive data: Passwords and private key passwords are marked as sensitive in the schema
Troubleshooting
Connection Refused
- Verify SSH service is running on the target server
- Check firewall settings and network connectivity
- Ensure the correct port is specified (default: 22)
Authentication Failed
- Verify username and password/SSH key are correct
- Check that the private key file exists and has correct permissions
- Ensure the SSH key is added to the server's
~/.ssh/authorized_keysfile
Timeout Errors
- Check network connectivity and latency
- Increase the
timeoutparameter value - Verify that the server is responsive and not overloaded
Permission Denied
- Ensure user has appropriate permissions on the remote server
- Check file and directory permissions for SFTP operations
- Verify SSH key permissions (typically 600 for private keys)
Contributing
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Issues: GitHub Issues
- Documentation: GitHub Wiki
Acknowledgments
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ssh_mcp_new-1.0.0.tar.gz.
File metadata
- Download URL: ssh_mcp_new-1.0.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8248b25d5a48355316ac638bbefcafb78af9b4aa1e5c22a9f6d8a0a3ddd3fff
|
|
| MD5 |
ac4b05de2188e1d8d9d495f951f8858e
|
|
| BLAKE2b-256 |
7f0fc3b1e0090c389af96e71c633a6d6d619a52d503d7c856c063c64d0258230
|
Provenance
The following attestation bundles were made for ssh_mcp_new-1.0.0.tar.gz:
Publisher:
publish.yml on ifindv/ssh-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ssh_mcp_new-1.0.0.tar.gz -
Subject digest:
a8248b25d5a48355316ac638bbefcafb78af9b4aa1e5c22a9f6d8a0a3ddd3fff - Sigstore transparency entry: 1301756945
- Sigstore integration time:
-
Permalink:
ifindv/ssh-mcp@f991b86b518af371101738c0724330eb160ae501 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ifindv
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f991b86b518af371101738c0724330eb160ae501 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ssh_mcp_new-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ssh_mcp_new-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a513828e446663c6402d6f89edad9656fab5dd3c383d966a532bbadb17d1dba
|
|
| MD5 |
92311178f733c43a7a81a9631f2000fb
|
|
| BLAKE2b-256 |
1e5a0cdde4f137ce29ab31b008270bb26dc7293cbda6a3fd4771ba8acd7fc0b8
|
Provenance
The following attestation bundles were made for ssh_mcp_new-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on ifindv/ssh-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ssh_mcp_new-1.0.0-py3-none-any.whl -
Subject digest:
0a513828e446663c6402d6f89edad9656fab5dd3c383d966a532bbadb17d1dba - Sigstore transparency entry: 1301757062
- Sigstore integration time:
-
Permalink:
ifindv/ssh-mcp@f991b86b518af371101738c0724330eb160ae501 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ifindv
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f991b86b518af371101738c0724330eb160ae501 -
Trigger Event:
workflow_dispatch
-
Statement type: