tools

package
v0.0.0-...-abd195e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TruncateOutput

func TruncateOutput(s string, maxBytes int) string

TruncateOutput truncates s to maxBytes and appends a truncation marker. If maxBytes <= 0 or len(s) <= maxBytes, s is returned unchanged. The truncation point is adjusted to avoid splitting a multi-byte UTF-8 character.

Types

type ConnectDeps

type ConnectDeps struct {
	Pool        *connection.Pool
	Auth        *connection.AuthDiscovery
	Filter      *security.Filter
	RateLimiter *security.RateLimiter
}

ConnectDeps holds dependencies for the ssh_connect tool handler.

type DisconnectDeps

type DisconnectDeps struct {
	Pool       *connection.Pool
	TermPool   *connection.TerminalPool
	TunnelPool *tunnel.TunnelPool
}

DisconnectDeps holds dependencies for the ssh_disconnect tool handler.

type DownloadDeps

type DownloadDeps struct {
	Pool         *connection.Pool
	LocalBaseDir string
	RateLimiter  *security.RateLimiter
}

DownloadDeps holds dependencies for the ssh_download tool handler.

type ExecuteDeps

type ExecuteDeps struct {
	Pool          *connection.Pool
	Filter        *security.Filter
	RateLimiter   *security.RateLimiter
	Config        *config.SSHConfig
	MaxOutputSize int
}

ExecuteDeps holds dependencies for the ssh_execute tool handler.

type FileEditDeps

type FileEditDeps struct {
	Pool        *connection.Pool
	RateLimiter *security.RateLimiter
	MaxFileSize int64
}

FileEditDeps holds dependencies for the ssh_edit_file tool handler.

type FileReadDeps

type FileReadDeps struct {
	Pool        *connection.Pool
	RateLimiter *security.RateLimiter
	MaxFileSize int64
}

FileReadDeps holds dependencies for the ssh_read_file tool handler.

type SSHCloseTerminalInput

type SSHCloseTerminalInput struct {
	TerminalID string `json:"terminal_id" jsonschema:"Terminal ID from ssh_open_terminal"`
}

SSHCloseTerminalInput is the input for the ssh_close_terminal tool.

type SSHCloseTerminalOutput

type SSHCloseTerminalOutput struct {
	Message string `json:"message"`
}

SSHCloseTerminalOutput is the output for the ssh_close_terminal tool.

func HandleCloseTerminal

func HandleCloseTerminal(ctx context.Context, deps *TerminalDeps, input SSHCloseTerminalInput) (*SSHCloseTerminalOutput, error)

HandleCloseTerminal closes an active PTY terminal session.

func (SSHCloseTerminalOutput) Text

func (o SSHCloseTerminalOutput) Text() string

Text returns a human-readable representation of the close terminal result.

type SSHConnectInput

type SSHConnectInput struct {
	Host     string `` /* 185-byte string literal not displayed */
	Port     int    `json:"port,omitempty" jsonschema:"Optional. SSH port override (default 22)"`
	User     string `json:"user,omitempty" jsonschema:"Optional. SSH username override (default: current OS user)"`
	Password string `json:"password,omitempty" jsonschema:"Optional. SSH password override"`
	KeyPath  string `json:"key_path,omitempty" jsonschema:"Optional. Path to SSH private key (default: auto-discovered from ~/.ssh/)"`
}

SSHConnectInput is the input for the ssh_connect tool.

type SSHConnectOutput

type SSHConnectOutput struct {
	SessionID          string `json:"session_id"`
	Host               string `json:"host"`
	Port               int    `json:"port"`
	User               string `json:"user"`
	Message            string `json:"message"`
	OS                 string `json:"os,omitempty"`
	Arch               string `json:"arch,omitempty"`
	Shell              string `json:"shell,omitempty"`
	PackageManager     string `json:"package_manager,omitempty"`
	SudoNoninteractive bool   `json:"sudo_noninteractive,omitempty"`
}

SSHConnectOutput is the output for the ssh_connect tool.

func HandleConnect

func HandleConnect(ctx context.Context, deps *ConnectDeps, input SSHConnectInput) (*SSHConnectOutput, error)

HandleConnect implements the ssh_connect tool.

func (SSHConnectOutput) Text

func (o SSHConnectOutput) Text() string

Text returns a human-readable representation of the connect result.

type SSHDisconnectInput

type SSHDisconnectInput struct {
	SessionID string `json:"session_id" jsonschema:"Session ID to disconnect"`
}

SSHDisconnectInput is the input for the ssh_disconnect tool.

type SSHDisconnectOutput

type SSHDisconnectOutput struct {
	Message string `json:"message"`
}

SSHDisconnectOutput is the output for the ssh_disconnect tool.

func HandleDisconnect

func HandleDisconnect(_ context.Context, deps *DisconnectDeps, input SSHDisconnectInput) (*SSHDisconnectOutput, error)

HandleDisconnect implements the ssh_disconnect tool.

func (SSHDisconnectOutput) Text

func (o SSHDisconnectOutput) Text() string

Text returns a human-readable representation of the disconnect result.

type SSHDownloadInput

type SSHDownloadInput struct {
	SessionID  string `json:"session_id" jsonschema:"Session ID from ssh_connect"`
	RemotePath string `json:"remote_path" jsonschema:"Remote file or directory path to download"`
	LocalPath  string `json:"local_path" jsonschema:"Local destination path"`
}

SSHDownloadInput is the input for the ssh_download tool.

type SSHDownloadOutput

type SSHDownloadOutput struct {
	FilesDownloaded int    `json:"files_downloaded"`
	BytesRead       int64  `json:"bytes_read"`
	Message         string `json:"message"`
}

SSHDownloadOutput is the output for the ssh_download tool.

func HandleDownload

func HandleDownload(ctx context.Context, deps *DownloadDeps, input SSHDownloadInput) (*SSHDownloadOutput, error)

HandleDownload implements the ssh_download tool. It auto-detects whether remote_path is a file or directory and delegates accordingly.

func (SSHDownloadOutput) Text

func (o SSHDownloadOutput) Text() string

Text returns a human-readable representation of the download result.

type SSHEditFileInput

type SSHEditFileInput struct {
	SessionID  string `json:"session_id" jsonschema:"Session ID from ssh_connect"`
	RemotePath string `json:"remote_path" jsonschema:"Remote file path to edit"`
	Mode       string `json:"mode,omitempty" jsonschema:"Edit mode: replace (full content) or patch (find and replace)"`
	Content    string `json:"content,omitempty" jsonschema:"Full file content (for replace mode)"`
	OldString  string `json:"old_string,omitempty" jsonschema:"String to find (for patch mode)"`
	NewString  string `json:"new_string,omitempty" jsonschema:"String to replace with (for patch mode)"`
	Backup     *bool  `json:"backup,omitempty" jsonschema:"Create .bak backup before editing (default true)"`
}

SSHEditFileInput is the input for the ssh_edit_file tool.

type SSHEditFileOutput

type SSHEditFileOutput struct {
	BytesWritten int64  `json:"bytes_written"`
	Message      string `json:"message"`
}

SSHEditFileOutput is the output for the ssh_edit_file tool.

func HandleEditFile

func HandleEditFile(ctx context.Context, deps *FileEditDeps, input SSHEditFileInput) (*SSHEditFileOutput, error)

HandleEditFile implements the ssh_edit_file tool.

func (SSHEditFileOutput) Text

func (o SSHEditFileOutput) Text() string

Text returns a human-readable representation of the edit result.

type SSHExecuteInput

type SSHExecuteInput struct {
	SessionID    string `json:"session_id" jsonschema:"Session ID from ssh_connect"`
	Command      string `json:"command" jsonschema:"Command to execute"`
	Timeout      int    `json:"timeout,omitempty" jsonschema:"Command timeout in seconds (default from config)"`
	Sudo         bool   `json:"sudo,omitempty" jsonschema:"Execute with sudo"`
	SudoPassword string `json:"sudo_password,omitempty" jsonschema:"Password for sudo (command is executed via 'sudo -S sh -c ...')"`
	WorkingDir   string `json:"working_dir,omitempty" jsonschema:"Working directory for command execution"`
}

SSHExecuteInput is the input for the ssh_execute tool.

type SSHExecuteOutput

type SSHExecuteOutput struct {
	Stdout     string `json:"stdout"`
	Stderr     string `json:"stderr"`
	ExitCode   int    `json:"exit_code"`
	DurationMs int64  `json:"duration_ms"`
}

SSHExecuteOutput is the output for the ssh_execute tool.

func HandleExecute

func HandleExecute(ctx context.Context, deps *ExecuteDeps, input SSHExecuteInput) (*SSHExecuteOutput, error)

HandleExecute implements the ssh_execute tool.

func (SSHExecuteOutput) Text

func (o SSHExecuteOutput) Text() string

Text returns a human-readable representation of the execute result.

type SSHListSessionsInput

type SSHListSessionsInput struct{}

SSHListSessionsInput is the input for ssh_list_sessions (empty, no parameters needed).

type SSHListSessionsOutput

type SSHListSessionsOutput struct {
	Sessions []SessionInfo `json:"sessions"`
	Count    int           `json:"count"`
}

SSHListSessionsOutput is the output for the ssh_list_sessions tool.

func HandleListSessions

func HandleListSessions(_ context.Context, deps *SessionsDeps, _ SSHListSessionsInput) (*SSHListSessionsOutput, error)

HandleListSessions implements the ssh_list_sessions tool. Access control: when HTTP transport is used, access is gated by the --http-token bearer auth middleware.

func (SSHListSessionsOutput) Text

func (o SSHListSessionsOutput) Text() string

Text returns a human-readable representation of the sessions list.

type SSHOpenTerminalInput

type SSHOpenTerminalInput struct {
	SessionID   string `json:"session_id" jsonschema:"Session ID from ssh_connect"`
	Cols        int    `json:"cols,omitempty" jsonschema:"Terminal width in columns (default 120)"`
	Rows        int    `json:"rows,omitempty" jsonschema:"Terminal height in rows (default 50)"`
	TermType    string `json:"term_type,omitempty" jsonschema:"Terminal type (default xterm-256color)"`
	WaitMs      int    `json:"wait_ms,omitempty" jsonschema:"Milliseconds to wait for initial output (default 500)"`
	ProtectExit *bool  `` /* 241-byte string literal not displayed */
}

SSHOpenTerminalInput is the input for the ssh_open_terminal tool.

type SSHOpenTerminalOutput

type SSHOpenTerminalOutput struct {
	TerminalID string `json:"terminal_id"`
	Output     string `json:"output"`
	Message    string `json:"message"`
}

SSHOpenTerminalOutput is the output for the ssh_open_terminal tool.

func HandleOpenTerminal

func HandleOpenTerminal(ctx context.Context, deps *TerminalDeps, input SSHOpenTerminalInput) (*SSHOpenTerminalOutput, error)

HandleOpenTerminal opens a new interactive PTY terminal session.

func (SSHOpenTerminalOutput) Text

func (o SSHOpenTerminalOutput) Text() string

Text returns a human-readable representation of the open terminal result.

type SSHReadFileInput

type SSHReadFileInput struct {
	SessionID  string `json:"session_id" jsonschema:"Session ID from ssh_connect"`
	RemotePath string `json:"remote_path" jsonschema:"Remote file path to read"`
	Offset     int    `json:"offset,omitempty" jsonschema:"Line offset to start reading from (1-based, default 1)"`
	Limit      int    `json:"limit,omitempty" jsonschema:"Maximum number of lines to return (default 0 = all lines)"`
	MaxSize    int64  `json:"max_size,omitempty" jsonschema:"Maximum file size in bytes (default from server config, 0=unlimited)"`
}

SSHReadFileInput is the input for the ssh_read_file tool.

type SSHReadFileOutput

type SSHReadFileOutput struct {
	Content    string `json:"content"`
	TotalLines int    `json:"total_lines"`
	FileSize   int64  `json:"file_size"`
	FromLine   int    `json:"from_line"`
	ToLine     int    `json:"to_line"`
	Message    string `json:"message"`
}

SSHReadFileOutput is the output for the ssh_read_file tool.

func HandleReadFile

func HandleReadFile(ctx context.Context, deps *FileReadDeps, input SSHReadFileInput) (*SSHReadFileOutput, error)

HandleReadFile implements the ssh_read_file tool.

func (SSHReadFileOutput) Text

func (o SSHReadFileOutput) Text() string

Text returns a human-readable representation of the read file result.

type SSHReadOutputInput

type SSHReadOutputInput struct {
	TerminalID string `json:"terminal_id" jsonschema:"Terminal ID from ssh_open_terminal"`
	WaitMs     int    `json:"wait_ms,omitempty" jsonschema:"Max milliseconds to wait for new output (default 0 = return immediately)"`
	Limit      int    `` /* 240-byte string literal not displayed */
}

SSHReadOutputInput is the input for the ssh_read_output tool.

type SSHReadOutputOutput

type SSHReadOutputOutput struct {
	Output  string `json:"output"`
	HasNew  bool   `json:"has_new"`
	Lines   int    `json:"lines,omitempty"`
	HasMore bool   `json:"has_more,omitempty"`
}

SSHReadOutputOutput is the output for the ssh_read_output tool.

func HandleReadOutput

func HandleReadOutput(ctx context.Context, deps *TerminalDeps, input SSHReadOutputInput) (*SSHReadOutputOutput, error)

HandleReadOutput reads buffered output from a terminal since the last read. When input.Limit > 0, output is capped at that many complete lines and any remaining lines stay in the buffer for the next call (paginated reads).

func (SSHReadOutputOutput) Text

func (o SSHReadOutputOutput) Text() string

Text returns a human-readable representation of the read output result. When the response is line-limited and more data remains buffered, a marker line is appended so the agent can spot the pagination boundary without parsing the JSON envelope.

type SSHSendInputInput

type SSHSendInputInput struct {
	TerminalID string `json:"terminal_id" jsonschema:"Terminal ID from ssh_open_terminal"`
	Text       string `` /* 227-byte string literal not displayed */
	SpecialKey string `` /* 152-byte string literal not displayed */
	WaitMs     int    `` /* 170-byte string literal not displayed */
}

SSHSendInputInput is the input for the ssh_send_input tool.

type SSHSendInputOutput

type SSHSendInputOutput struct {
	Output  string `json:"output"`
	Written int    `json:"bytes_written"`
}

SSHSendInputOutput is the output for the ssh_send_input tool.

func HandleSendInput

func HandleSendInput(ctx context.Context, deps *TerminalDeps, input SSHSendInputInput) (*SSHSendInputOutput, error)

HandleSendInput writes text or a special key to a terminal's stdin and reads back new output.

func (SSHSendInputOutput) Text

func (o SSHSendInputOutput) Text() string

Text returns a human-readable representation of the send input result.

type SSHTunnelCloseInput

type SSHTunnelCloseInput struct {
	TunnelID string `json:"tunnel_id" jsonschema:"Tunnel ID from ssh_tunnel_create"`
}

SSHTunnelCloseInput is the input for the ssh_tunnel_close tool.

type SSHTunnelCloseOutput

type SSHTunnelCloseOutput struct {
	Message string `json:"message"`
}

SSHTunnelCloseOutput is the output for the ssh_tunnel_close tool.

func HandleTunnelClose

func HandleTunnelClose(_ context.Context, deps *TunnelDeps, input SSHTunnelCloseInput) (*SSHTunnelCloseOutput, error)

HandleTunnelClose closes an active tunnel.

func (SSHTunnelCloseOutput) Text

func (o SSHTunnelCloseOutput) Text() string

Text returns a human-readable representation of the tunnel close result.

type SSHTunnelCreateInput

type SSHTunnelCreateInput struct {
	SessionID  string `json:"session_id" jsonschema:"Session ID from ssh_connect"`
	RemoteAddr string `json:"remote_addr" jsonschema:"Remote address to forward to (e.g. localhost:5432, 10.0.0.1:80)"`
	LocalPort  int    `json:"local_port,omitempty" jsonschema:"Local port to listen on (0 = auto-assign a free port)"`
}

SSHTunnelCreateInput is the input for the ssh_tunnel_create tool.

type SSHTunnelCreateOutput

type SSHTunnelCreateOutput struct {
	TunnelID   string `json:"tunnel_id"`
	LocalAddr  string `json:"local_addr"`
	LocalPort  int    `json:"local_port"`
	RemoteAddr string `json:"remote_addr"`
	Message    string `json:"message"`
}

SSHTunnelCreateOutput is the output for the ssh_tunnel_create tool.

func HandleTunnelCreate

func HandleTunnelCreate(ctx context.Context, deps *TunnelDeps, input SSHTunnelCreateInput) (*SSHTunnelCreateOutput, error)

HandleTunnelCreate creates a new local port forwarding tunnel.

func (SSHTunnelCreateOutput) Text

func (o SSHTunnelCreateOutput) Text() string

Text returns a human-readable representation of the tunnel create result.

type SSHTunnelListInput

type SSHTunnelListInput struct {
	SessionID string `json:"session_id,omitempty" jsonschema:"Optional. Filter tunnels by session ID"`
}

SSHTunnelListInput is the input for the ssh_tunnel_list tool.

type SSHTunnelListOutput

type SSHTunnelListOutput struct {
	Tunnels []TunnelInfoOutput `json:"tunnels"`
	Count   int                `json:"count"`
}

SSHTunnelListOutput is the output for the ssh_tunnel_list tool.

func HandleTunnelList

func HandleTunnelList(_ context.Context, deps *TunnelDeps, input SSHTunnelListInput) (*SSHTunnelListOutput, error)

HandleTunnelList lists active tunnels, optionally filtered by session ID.

func (SSHTunnelListOutput) Text

func (o SSHTunnelListOutput) Text() string

Text returns a human-readable representation of the tunnel list result.

type SSHUploadInput

type SSHUploadInput struct {
	SessionID  string `json:"session_id" jsonschema:"Session ID from ssh_connect"`
	LocalPath  string `json:"local_path" jsonschema:"Local file or directory path to upload"`
	RemotePath string `json:"remote_path" jsonschema:"Remote destination path"`
}

SSHUploadInput is the input for the ssh_upload tool.

type SSHUploadOutput

type SSHUploadOutput struct {
	FilesUploaded int    `json:"files_uploaded"`
	BytesWritten  int64  `json:"bytes_written"`
	Message       string `json:"message"`
}

SSHUploadOutput is the output for the ssh_upload tool.

func HandleUpload

func HandleUpload(ctx context.Context, deps *UploadDeps, input SSHUploadInput) (*SSHUploadOutput, error)

HandleUpload implements the ssh_upload tool. It auto-detects whether local_path is a file or directory and delegates accordingly.

func (SSHUploadOutput) Text

func (o SSHUploadOutput) Text() string

Text returns a human-readable representation of the upload result.

type SessionInfo

type SessionInfo struct {
	SessionID          string               `json:"session_id"`
	Host               string               `json:"host"`
	Port               int                  `json:"port"`
	User               string               `json:"user"`
	ConnectedAt        string               `json:"connected_at"`
	LastUsed           string               `json:"last_used"`
	CommandCount       int                  `json:"command_count"`
	Connected          bool                 `json:"connected"`
	OS                 string               `json:"os,omitempty"`
	Arch               string               `json:"arch,omitempty"`
	Shell              string               `json:"shell,omitempty"`
	PackageManager     string               `json:"package_manager,omitempty"`
	SudoNoninteractive bool                 `json:"sudo_noninteractive,omitempty"`
	Terminals          []TerminalInfoOutput `json:"terminals,omitempty"`
	Tunnels            []TunnelInfoOutput   `json:"tunnels,omitempty"`
}

SessionInfo provides information about an active session.

type SessionsDeps

type SessionsDeps struct {
	Pool       *connection.Pool
	TermPool   *connection.TerminalPool
	TunnelPool *tunnel.TunnelPool
}

SessionsDeps holds dependencies for the ssh_list_sessions tool handler.

type TerminalDeps

type TerminalDeps struct {
	Pool          *connection.Pool
	TermPool      *connection.TerminalPool
	RateLimiter   *security.RateLimiter
	MaxOutputSize int
}

TerminalDeps holds dependencies for terminal tool handlers.

type TerminalInfoOutput

type TerminalInfoOutput struct {
	TerminalID string `json:"terminal_id"`
	SessionID  string `json:"session_id"`
	CreatedAt  string `json:"created_at"`
	LastUsed   string `json:"last_used"`
}

TerminalInfoOutput provides information about an active terminal session.

type TunnelDeps

type TunnelDeps struct {
	Pool        *connection.Pool
	TunnelPool  *tunnel.TunnelPool
	RateLimiter *security.RateLimiter
}

TunnelDeps holds dependencies for tunnel tool handlers.

type TunnelInfoOutput

type TunnelInfoOutput struct {
	TunnelID   string `json:"tunnel_id"`
	SessionID  string `json:"session_id"`
	LocalAddr  string `json:"local_addr"`
	RemoteAddr string `json:"remote_addr"`
	ConnCount  int64  `json:"conn_count"`
	CreatedAt  string `json:"created_at"`
	LastUsed   string `json:"last_used"`
}

TunnelInfoOutput provides information about an active tunnel.

type UploadDeps

type UploadDeps struct {
	Pool         *connection.Pool
	LocalBaseDir string
	RateLimiter  *security.RateLimiter
}

UploadDeps holds dependencies for the ssh_upload tool handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址