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 (`exec` tool)
10//! - Support for `sudo` command execution with password (`sudo-exec` tool)
11//! - Persistent SSH connection with auto-reconnect
12//! - Configurable command timeout
13//! - Command length limits for safety
14//!
15//! # MCP Tools
16//!
17//! - `exec` - Execute a shell command on the remote SSH server
18//! - `sudo-exec` - Execute a command with sudo privileges (can be disabled with `--disable-sudo`)
19//! - `read-file` - Read a remote UTF-8 file with preview/head/tail/full modes
20//! - `write-file` - Atomically overwrite or create a remote UTF-8 file
21//! - `replace-in-file` - Atomically replace text within a remote UTF-8 file
22//!
23//! # Example Usage (CLI)
24//!
25//! ```bash
26//! ssh-mcp --host=192.168.1.100 --user=admin --password=secret
27//! ```
28//!
29//! # Example Usage (MCP Inspector)
30//!
31//! ```bash
32//! npx @modelcontextprotocol/inspector ./target/release/ssh-mcp -- \
33//!   --host=YOUR_HOST --user=root --password=pass
34//! ```
35
36pub mod background;
37pub mod config;
38pub mod error;
39pub mod logging;
40#[cfg(unix)]
41pub(crate) mod platform;
42pub mod server;
43mod shell_escape;
44pub mod ssh;
45pub mod ticket;
46pub mod tools;
47pub mod transfer;
48pub(crate) mod validate;
49
50// Re-exports for convenience
51pub use config::{Args, Config};
52pub use error::{Result, SshMcpError};
53pub use server::SshMcpServer;
54pub use ssh::{
55    CommandOutput, HostKeyCheckMode, SshConfig, SshConnectionManager, SshHandler,
56    escape_command_for_shell, escape_for_shell, escape_for_timeout_wrapper, sanitize_command,
57    sanitize_password, wrap_command_with_timeout, wrap_sudo_command,
58};
59pub use tools::{CheckProcessParams, ExecParams, SudoExecParams};