Skip to main content

ssh_mcp/
lib.rs

1//! SSH MCP Server - A Model Context Protocol server for remote SSH command execution
2//!
3//! This crate provides an MCP server that allows executing commands on remote Linux
4//! systems via SSH. It supports both password and key-based authentication, as well
5//! as privilege elevation via `su` and `sudo`.
6//!
7//! # Features
8//!
9//! - Execute shell commands on remote SSH servers (`shell` tool)
10//! - Support for `sudo` command execution with password (`sudo_shell` tool)
11//! - Persistent SSH connection with auto-reconnect
12//! - Configurable command timeout
13//! - Command length limits for safety
14//!
15//! # MCP Tools
16//!
17//! - `shell` - Execute a shell command on the remote SSH server
18//! - `sudo_shell` - Execute a command with sudo privileges (can be disabled with `--disable-sudo`)
19//! - `check_process` - Monitor background commands and read their local logs
20//! - `transfer` - Transfer files and directories over SSH
21//! - `read` - Read a remote UTF-8 file with preview/head/tail/full modes
22//! - `apply_patch` - Create, update, or delete one remote UTF-8 text file
23//! - `sudo_apply_patch` - Apply an exact remote file patch under sudo (can be disabled with `--disable-sudo`)
24//!
25//! # Example Usage (CLI)
26//!
27//! ```bash
28//! ssh-mcp --host=192.168.1.100 --user=admin --password=secret
29//! ```
30//!
31//! # Example Usage (MCP Inspector)
32//!
33//! ```bash
34//! npx @modelcontextprotocol/inspector ./target/release/ssh-mcp -- \
35//!   --host=YOUR_HOST --user=root --password=pass
36//! ```
37
38pub mod background;
39pub mod config;
40pub mod error;
41pub mod logging;
42pub(crate) mod patch;
43#[cfg(unix)]
44pub(crate) mod platform;
45pub mod server;
46mod shell_escape;
47pub mod ssh;
48pub mod tools;
49pub mod transfer;
50pub(crate) mod validate;
51
52// Re-exports for convenience
53pub use config::{Args, Config};
54pub use error::{Result, SshMcpError};
55pub use server::SshMcpServer;
56pub use ssh::{
57    CommandOutput, HostKeyCheckMode, SshConfig, SshConnectionManager, SshHandler,
58    escape_command_for_shell, escape_for_shell, escape_for_timeout_wrapper, sanitize_command,
59    sanitize_password, wrap_command_with_timeout, wrap_sudo_command,
60};
61pub use tools::{CheckProcessParams, ExecParams, SudoExecParams};