cnctd-service-ssh 0.1.8

SSH command execution service - library and MCP server
Documentation
//! cnctd-service-ssh - SSH command execution library
//!
//! This library provides secure SSH command execution capabilities,
//! including interactive shell sessions for LLM agents.
//!
//! # Library Usage
//!
//! ```rust,no_run
//! 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
//!
//! ```rust,no_run
//! 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):
//!
//! ```rust
//! 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:
//! ```bash
//! cnctd-service-ssh
//! ```

pub mod operations;
pub mod service_error;
pub mod sessions;

#[cfg(feature = "mcp")]
pub mod mcp;

// Re-export main types for convenience
pub use operations::{
    SshRegisterArgs,
    SshExecArgs,
    SshUnregisterArgs,
    SshExecResult,
    SshService,
    ToolDefinition,
    get_tool_definitions,
    // Legacy global functions for backwards compatibility
    ssh_register,
    ssh_exec,
    ssh_unregister,
};

pub use service_error::ServiceError;

// Re-export sessions types
pub use sessions::{
    ShellSessionService,
    types::{
        ShellSessionCreateArgs,
        ShellSessionWriteArgs,
        ShellSessionReadArgs,
        ShellSessionListArgs,
        ShellSessionReconnectArgs,
        ShellSessionResizeArgs,
        ShellSessionCloseArgs,
        ShellSessionCreateResult,
        ShellSessionWriteResult,
        ShellSessionReadResult,
        ShellSessionListResult,
        ShellSessionReconnectResult,
        ShellSessionResizeResult,
        ShellSessionCloseResult,
        ShellSessionInfo,
        ScreenState,
        SessionState,
        OutputFormat,
    },
    get_shell_session_tool_definitions,
    // Global functions for MCP server
    shell_session_create,
    shell_session_write,
    shell_session_read,
    shell_session_list,
    shell_session_reconnect,
    shell_session_resize,
    shell_session_close,
};

/// Get all tool definitions (SSH exec + interactive sessions)
pub fn get_all_tool_definitions() -> Vec<ToolDefinition> {
    let mut tools = get_tool_definitions();
    tools.extend(get_shell_session_tool_definitions());
    tools
}