Expand description
cnctd-service-ssh - SSH command execution library
This library provides secure SSH command execution capabilities, including interactive shell sessions for LLM agents.
§Library Usage
use cnctd_service_ssh::{SshService, SshRegisterArgs, SshExecArgs};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let service = SshService::new();
// Register a target
service.register(SshRegisterArgs {
id: "my-server".to_string(),
host: "example.com".to_string(),
user: "ubuntu".to_string(),
port: 22,
key_passphrase: None,
known_hosts_path: "~/.ssh/known_hosts".to_string(),
client_id: Some("my-app".to_string()),
}).await?;
// Execute a command
let result = service.exec(SshExecArgs {
id: "my-server".to_string(),
command: "hostname".to_string(),
timeout_secs: 30,
context: Some("checking hostname".to_string()),
}).await?;
println!("Output: {}", result.stdout);
Ok(())
}§Interactive Shell Sessions
use cnctd_service_ssh::sessions::{ShellSessionService, ShellSessionCreateArgs};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let shell_service = ShellSessionService::global();
// Create an interactive shell session
let result = shell_service.create(ShellSessionCreateArgs {
target_id: "my-server".to_string(),
name: Some("dev-shell".to_string()),
shell: None, // Use default login shell
cols: 120,
rows: 40,
client_id: Some("my-app".to_string()),
env: Default::default(),
}).await?;
println!("Session created: {}", result.session_id);
Ok(())
}§Tool Definitions
To get tool schemas for LLM integration (avoiding hardcoded schemas):
use cnctd_service_ssh::{get_tool_definitions, get_all_tool_definitions};
// Get only SSH exec tools
let ssh_tools = get_tool_definitions();
// Get all tools including interactive shell sessions
let all_tools = get_all_tool_definitions();§MCP Server
Run as a standalone MCP server:
cnctd-service-sshRe-exports§
pub use operations::SshRegisterArgs;pub use operations::SshExecArgs;pub use operations::SshUnregisterArgs;pub use operations::SshExecResult;pub use operations::SshService;pub use operations::ToolDefinition;pub use operations::get_tool_definitions;pub use operations::ssh_register;pub use operations::ssh_exec;pub use operations::ssh_unregister;pub use service_error::ServiceError;pub use sessions::ShellSessionService;pub use sessions::types::ShellSessionCreateArgs;pub use sessions::types::ShellSessionWriteArgs;pub use sessions::types::ShellSessionReadArgs;pub use sessions::types::ShellSessionListArgs;pub use sessions::types::ShellSessionReconnectArgs;pub use sessions::types::ShellSessionResizeArgs;pub use sessions::types::ShellSessionCloseArgs;pub use sessions::types::ShellSessionCreateResult;pub use sessions::types::ShellSessionWriteResult;pub use sessions::types::ShellSessionReadResult;pub use sessions::types::ShellSessionListResult;pub use sessions::types::ShellSessionReconnectResult;pub use sessions::types::ShellSessionResizeResult;pub use sessions::types::ShellSessionCloseResult;pub use sessions::types::ShellSessionInfo;pub use sessions::types::ScreenState;pub use sessions::types::SessionState;pub use sessions::types::OutputFormat;pub use sessions::get_shell_session_tool_definitions;pub use sessions::shell_session_create;pub use sessions::shell_session_write;pub use sessions::shell_session_read;pub use sessions::shell_session_list;pub use sessions::shell_session_reconnect;pub use sessions::shell_session_resize;pub use sessions::shell_session_close;
Modules§
- mcp
- MCP (Model Context Protocol) server implementation for the SSH service.
- operations
- Business logic for the SSH service.
- service_
error - Error types for the SSH service.
- sessions
- Interactive shell session management.
Functions§
- get_
all_ tool_ definitions - Get all tool definitions (SSH exec + interactive sessions)