A full-fledged Model Context Protocol (MCP) server that enables SSH connections and command execution on remote servers. This server implements all standard MCP protocols using FastMCP and provides a robust interface for managing SSH connections.
- Full MCP Protocol Support: Implements all standard MCP protocols including tools, resources, and prompts using FastMCP
- SSH Connection Management: Connect to multiple remote servers simultaneously with connection pooling
- Command Execution: Execute commands on remote servers with real-time output and interactive command support
- File Operations: Upload, download, list, delete, and create files/directories on remote servers
- Connection Pooling: Efficient management of multiple SSH connections with configurable limits
- Security: Support for password, key-based, and interactive authentication
- Logging: Comprehensive structured logging with configurable levels
- Error Handling: Robust error handling and recovery mechanisms
- Async Support: Full async/await support for all operations
- Python 3.10 or higher
- uv package manager (recommended) or pip
# Using uv (recommended)
uv sync
# Using pip
pip install -e .
# Build the package
uv build
# This creates a wheel file in dist/ directory
# Example: dist/mcp_ssh_server-1.0.0-py3-none-any.whl
# Install from the built wheel
pip install dist/mcp_ssh_server-1.0.0-py3-none-any.whl
# Or install from the current directory
pip install -e .
# Run the MCP server in stdio mode (for Claude Desktop, mcp dev, etc.)
python -m mcp_ssh_server
# Or using the helper script for inspectors / installers
mcp dev server.py
# Or using the installed script
mcp-ssh-server
# Run the MCP server in stdio mode (for Claude Desktop, mcp dev, etc.)
python -m mcp_ssh_server
# Or using the helper script for inspectors / installers
mcp dev server.py
# Or using the installed script
mcp-ssh-server
Create a configuration file config.json
in the project directory:
{
"server": {
"host": "localhost",
"port": 8080,
"log_level": "INFO"
},
"ssh": {
"default_timeout": 30,
"max_connections": 10,
"connection_pool_size": 5
}
}
This server implements the following MCP protocols using FastMCP:
ssh_connect
: Establish SSH connection to a remote serverssh_execute
: Execute commands on remote serversssh_execute_interactive
: Execute multiple commands interactivelyssh_upload
: Upload files to remote serversssh_download
: Download files from remote serversssh_list_files
: List files and directories on remote serversssh_delete_file
: Delete files on remote serversssh_create_directory
: Create directories on remote serversssh_disconnect
: Close SSH connectionsssh_list_connections
: List active SSH connections
ssh://connections
: Resource providing list of active SSH connections
ssh_command_prompt
: Interactive prompt for SSH command executionssh_file_operation_prompt
: Interactive prompt for file operations
# Connect to a remote server
{
"method": "tools/call",
"params": {
"name": "ssh_connect",
"arguments": {
"host": "example.com",
"port": 22,
"username": "user",
"password": "password",
"connection_id": "conn1",
"timeout": 30
}
}
}
# Execute a command on remote server
{
"method": "tools/call",
"params": {
"name": "ssh_execute",
"arguments": {
"connection_id": "conn1",
"command": "ls -la",
"timeout": 30
}
}
}
# Execute multiple commands interactively
{
"method": "tools/call",
"params": {
"name": "ssh_execute_interactive",
"arguments": {
"connection_id": "conn1",
"commands": ["cd /tmp", "ls -la", "pwd"],
"timeout": 30
}
}
}
# Upload a file
{
"method": "tools/call",
"params": {
"name": "ssh_upload",
"arguments": {
"connection_id": "conn1",
"local_path": "/path/to/local/file.txt",
"remote_path": "/remote/path/file.txt"
}
}
}
# Download a file
{
"method": "tools/call",
"params": {
"name": "ssh_download",
"arguments": {
"connection_id": "conn1",
"remote_path": "/remote/path/file.txt",
"local_path": "/path/to/local/file.txt"
}
}
}
# List files
{
"method": "tools/call",
"params": {
"name": "ssh_list_files",
"arguments": {
"connection_id": "conn1",
"remote_path": "/tmp"
}
}
}
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
Run the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=mcp_ssh_server --cov-report=term-missing --cov-report=html
# Run specific test file
pytest tests/test_ssh_manager.py
# Test server initialization
python test_server.py
This server uses FastMCP for a modern, streamlined MCP implementation:
- All tools are implemented as async functions using
@mcp.tool()
decorators - Resources are implemented using
@mcp.resource()
decorators - Prompts are implemented using
@mcp.prompt()
decorators - Proper async/await handling throughout the codebase
- No blocking operations in tool handlers
The SSH manager provides:
- Connection pooling with configurable limits
- Automatic connection cleanup
- Support for multiple authentication methods
- Comprehensive error handling and logging
- Async operations for all SSH interactions
- All operations return structured error responses
- Comprehensive logging for debugging
- Graceful handling of connection failures
- Timeout protection for all operations
- Passwords are handled securely and not logged
- SSH keys are stored securely
- Connection timeouts prevent hanging connections
- Input validation prevents command injection
- All operations are logged for audit purposes
- Async operations prevent blocking the event loop
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
For issues and questions, please open an issue on the GitHub repository.