UNPKG

mcp-ssh-tool

Version:

Model Context Protocol (MCP) SSH client server for remote automation

78 lines (77 loc) 1.98 kB
import { NodeSSH } from 'node-ssh'; import SftpClient from 'ssh2-sftp-client'; import { ConnectionParams, SessionInfo, SessionResult } from './types.js'; /** * SSH session with connection and SFTP client */ export interface SSHSession { ssh: NodeSSH; sftp: SftpClient; info: SessionInfo; } /** * Session manager with LRU cache and TTL */ export declare class SessionManager { private sessions; private readonly maxSessions; private sessionCounter; constructor(maxSessions?: number); /** * Opens a new SSH session with authentication */ openSession(params: ConnectionParams): Promise<SessionResult>; /** * Closes an SSH session */ closeSession(sessionId: string): Promise<boolean>; /** * Gets an active session by ID */ getSession(sessionId: string): SSHSession | undefined; /** * Builds authentication configuration based on the auth strategy */ private buildAuthConfig; /** * Builds key-based authentication */ private buildKeyAuth; /** * Builds SSH agent authentication */ private buildAgentAuth; /** * Builds automatic authentication (tries password, then key, then agent) */ private buildAutoAuth; /** * Loads private key from file path */ private loadPrivateKeyFromPath; /** * Auto-discovers private keys in standard locations */ private discoverPrivateKeys; /** * Generates a unique session ID */ private generateSessionId; /** * Evicts the oldest (least recently used) session */ private evictOldestSession; /** * Cleans up expired sessions */ private cleanupExpiredSessions; /** * Gets information about all active sessions */ getActiveSessions(): SessionInfo[]; /** * Closes all active sessions */ closeAllSessions(): Promise<void>; } export declare const sessionManager: SessionManager;