π A modern, FastMCP-based SSH server implementation for Model Context Protocol (MCP)
FastMCP SSH Server is a Python implementation of an SSH server for the Model Context Protocol, providing seamless SSH connection management and command execution capabilities for AI models. This is a complete re-implementation of the TypeScript version with enhanced features and improved performance.
- Multi-SSH Connection Management: Connect to multiple SSH servers simultaneously
- FastMCP Integration: Native integration with FastMCP framework for optimal performance
- Authentication Methods: Support for password and private key authentication
- Security Validation: Command whitelist/blacklist with regex pattern matching
- File Transfer: Secure SFTP upload and download operations
- Async Architecture: Full async/await support for high performance
- Command Filtering: Configurable whitelist and blacklist for command security
- Connection Validation: Comprehensive SSH connection parameter validation
- Error Handling: Robust error handling with detailed logging
- Secure Credentials: Support for private key authentication with passphrase protection
- Connection Pooling: Efficient connection reuse and management
- Singleton Pattern: Centralized connection management
- Timeout Controls: Configurable timeouts for all operations
- Resource Cleanup: Automatic cleanup of connections and resources
- Python 3.12+ (recommended)
- uv package manager (recommended) or pip
- AsyncSSH for SSH connections
- FastMCP framework
# Install from source
git clone https://github.com/your-username/fastmcp-ssh-server.git
cd fastmcp-ssh-server
# Install with uv
uv sync
# Or install in development mode
uv sync --dev# Install from source
git clone https://github.com/your-username/fastmcp-ssh-server.git
cd fastmcp-ssh-server
# Install dependencies
pip install -e .
# Or with development dependencies
pip install -e ".[dev]"# Will be available when published
pip install fastmcp-ssh-server# Single connection mode
fastmcp-ssh-server --host example.com --username myuser --password mypass
# Multiple connection mode using SSH connection strings
fastmcp-ssh-server user1@server1.com:22 user2@server2.com:2222
# With private key authentication
fastmcp-ssh-server --host server.com --username user --private-key ~/.ssh/id_rsa# With command restrictions
fastmcp-ssh-server \
--host example.com \
--username user \
--password pass \
--whitelist "ls,pwd,echo.*" \
--blacklist "rm.*,sudo.*"# config.yaml
servers:
production:
host: prod.example.com
port: 22
username: deploy
private_key: ~/.ssh/prod_key
whitelist: ["git.*", "npm.*", "node.*"]
blacklist: ["rm.*", "sudo.*"]
staging:
host: staging.example.com
port: 2222
username: dev
password: dev_password
whitelist: ["*"]
blacklist: ["rm -rf"]The FastMCP SSH Server provides a flexible CLI with support for both single and multiple connection modes.
fastmcp-ssh-server [OPTIONS]
Options:
-h, --host TEXT SSH hostname
-p, --port INTEGER SSH port (default: 22)
-u, --username TEXT SSH username
-w, --password TEXT SSH password
-k, --private-key TEXT SSH private key file path
-P, --passphrase TEXT SSH private key passphrase
-W, --whitelist TEXT Command whitelist patterns (comma-separated)
-B, --blacklist TEXT Command blacklist patterns (comma-separated)
--help Show help and exit# Format: [user@]host[:port]
fastmcp-ssh-server user1@server1.com:22 user2@server2.com:2222# Apply security settings to all connections
fastmcp-ssh-server --whitelist "ls,pwd,cat" --blacklist "rm,sudo" \
user1@server1.com user2@server2.comThe server provides four main MCP tools:
Execute commands on SSH servers with security validation.
{
"tool": "execute-command",
"arguments": {
"cmdString": "ls -la /home",
"serverName": "production",
"timeout": 30
}
}Upload files to SSH servers via SFTP.
{
"tool": "upload",
"arguments": {
"localPath": "/local/file.txt",
"remotePath": "/remote/path/file.txt",
"serverName": "production"
}
}Download files from SSH servers via SFTP.
{
"tool": "download",
"arguments": {
"remotePath": "/remote/path/file.txt",
"localPath": "/local/file.txt",
"serverName": "production"
}
}List all configured SSH servers and their status.
{
"tool": "list-servers",
"arguments": {}
}- Use regex patterns to allow specific commands
["ls.*", "echo.*", "pwd"]- Allow ls, echo commands and pwd["*"]- Allow all commands (use with blacklist)
- Use regex patterns to deny specific commands
["rm.*", "sudo.*"]- Deny rm and sudo commands[".*--force.*"]- Deny any command with --force flag
# Development environment - restrictive
--whitelist "git.*,npm.*,node.*,python.*" \
--blacklist ".*--force.*,rm.*"
# Production environment - very restrictive
--whitelist "ls,pwd,cat,grep" \
--blacklist "rm.*,sudo.*,chmod.*"
# Staging environment - moderate
--whitelist "*" \
--blacklist "rm -rf.*,sudo su.*,dd.*"fastmcp-ssh-server --host server.com --username user --password secret# Without passphrase
fastmcp-ssh-server --host server.com --username user --private-key ~/.ssh/id_rsa
# With passphrase
fastmcp-ssh-server --host server.com --username user \
--private-key ~/.ssh/id_rsa --passphrase mypassphrase# Use global password for connection strings without explicit auth
fastmcp-ssh-server --password globalpass \
user1@server1.com \
user2@server2.com# Clone the repository
git clone https://github.com/your-username/fastmcp-ssh-server.git
cd fastmcp-ssh-server
# Install with development dependencies
uv sync --dev
# Or with pip
pip install -e ".[dev]"# Run all tests with coverage
python tests/run_tests.py
# Run specific test categories
python tests/run_tests.py --unit # Unit tests only
python tests/run_tests.py --integration # Integration tests only
python tests/run_tests.py --fast # Fast tests only
# Run with verbose output
python tests/run_tests.py --verbose
# Generate coverage report
python tests/run_tests.py --coverage# Run linting and formatting
python tests/run_tests.py --lint
# Or run tools individually
ruff check src/
black src/
isort src/
mypy src/fastmcp-ssh-server/
βββ src/
β βββ python_ssh_mcp/
β βββ __init__.py # Package initialization
β βββ __main__.py # Module entry point
β βββ main.py # Main application entry
β βββ server.py # SSH MCP server implementation
β βββ ssh_manager.py # SSH connection manager
β βββ cli.py # Command line interface
β βββ models.py # Pydantic data models
β βββ tools/ # MCP tools implementation
β β βββ __init__.py
β β βββ execute_command.py
β β βββ upload.py
β β βββ download.py
β β βββ list_servers.py
β βββ utils/ # Utility modules
β βββ __init__.py
β βββ logger.py # Logging system
β βββ error_handling.py
βββ tests/ # Test suite
βββ docs/ # Documentation
βββ examples/ # Usage examples
βββ pyproject.toml # Project configuration
βββ README_PYTHON.md # This file
- API Documentation - Detailed MCP tools API reference
- Migration Guide - Migrating from TypeScript version
- Examples - Usage examples and configurations
- Test Documentation - Testing guide and coverage
- Troubleshooting - Common issues and solutions
This Python implementation is designed to be fully compatible with the TypeScript version. See our Migration Guide for detailed instructions on switching from the TypeScript implementation.
| Feature | TypeScript | Python |
|---|---|---|
| Framework | Native TS | FastMCP |
| Performance | Good | Enhanced |
| Async Support | Promise-based | Native async/await |
| Type Safety | TypeScript | Pydantic |
| Testing | Jest | pytest |
| Packaging | npm | pip/uv |
All MCP tools maintain the same interface:
- β
execute-command- Full compatibility - β
upload- Full compatibility - β
download- Full compatibility - β
list-servers- Full compatibility
# Build Docker image
docker build -t fastmcp-ssh-server .
# Run container
docker run -d --name ssh-mcp-server \
-e SSH_HOST=example.com \
-e SSH_USER=myuser \
-e SSH_PASS=mypass \
fastmcp-ssh-server# /etc/systemd/system/fastmcp-ssh-server.service
[Unit]
Description=FastMCP SSH Server
After=network.target
[Service]
Type=simple
User=mcp
WorkingDirectory=/opt/fastmcp-ssh-server
ExecStart=/opt/fastmcp-ssh-server/.venv/bin/fastmcp-ssh-server \
--host prod.example.com \
--username deploy \
--private-key /opt/fastmcp-ssh-server/keys/deploy.key
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target- Security: Use private key authentication in production
- Logging: Configure structured logging with log rotation
- Monitoring: Set up health checks and monitoring
- Backup: Regular backup of configuration and keys
- Updates: Automated update strategy
# Test SSH connection manually
ssh user@host -p port
# Check SSH key permissions
chmod 600 ~/.ssh/id_rsa
# Verbose SSH debugging
ssh -v user@host# Check file permissions
ls -la /path/to/private/key
# Fix key permissions
chmod 600 /path/to/private/key
chmod 700 ~/.ssh# Test command validation
fastmcp-ssh-server --host server.com --username user --password pass \
--whitelist "ls.*" --blacklist "rm.*"For more detailed troubleshooting, see docs/troubleshooting.md.
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
- Python 3.12+ compatibility
- Type hints for all functions
- Comprehensive tests with 90%+ coverage
- Documentation for all public APIs
- Security first approach
This project is licensed under the ISC License - see the LICENSE file for details.
- FastMCP - The excellent MCP framework
- AsyncSSH - Robust SSH implementation
- Pydantic - Data validation and settings
- Typer - Modern CLI framework
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: docs/
FastMCP SSH Server - Empowering AI models with secure, efficient SSH connectivity π