Skip to main content

ssh_mcp/
lib.rs

1//! SeSSHion - A lightweight SSH MCP server for LLM agents
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 command and transfer jobs
20//! - `transfer` - Transfer files and directories over SSH, optionally in the background
21//! - `apply_patch` - Create, update, or delete one remote UTF-8 text file
22//! - `sudo_apply_patch` - Apply an exact remote file patch under sudo (can be disabled with `--disable-sudo`)
23//!
24//! # Example Usage (CLI)
25//!
26//! ```bash
27//! ssh-mcp --host=192.168.1.100 --user=admin --password=secret
28//! ```
29//!
30//! # Example Usage (MCP Inspector)
31//!
32//! ```bash
33//! npx @modelcontextprotocol/inspector ./target/release/ssh-mcp -- \
34//!   --host=YOUR_HOST --user=root --password=pass
35//! ```
36
37pub mod background;
38pub mod config;
39pub mod error;
40pub mod logging;
41pub(crate) mod patch;
42#[cfg(unix)]
43pub(crate) mod platform;
44pub mod server;
45mod shell_escape;
46pub mod ssh;
47pub mod tools;
48pub mod transfer;
49pub(crate) mod validate;
50
51// Re-exports for convenience
52pub use config::{Args, Config};
53pub use error::{Result, SshMcpError};
54pub use server::SshMcpServer;
55pub use ssh::{
56    CommandOutput, HostKeyCheckMode, SshConfig, SshConnectionManager, SshHandler,
57    escape_command_for_shell, escape_for_shell, escape_for_timeout_wrapper, sanitize_command,
58    sanitize_password, wrap_command_with_timeout, wrap_sudo_command,
59};
60pub use tools::{CheckProcessParams, ExecParams, SudoExecParams};