ssh_connect
Establish SSH connections to VPS using IP, username, and optional password or private key. Enables secure access for initial setup, service installation, and configuration management.
Instructions
Connect to a VPS via SSH using password or private key
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | Yes | VPS IP address or hostname | |
| passphrase | No | Private key passphrase (optional) | |
| password | No | SSH password (optional) | |
| port | No | SSH port (default: 22) | |
| privateKeyPath | No | Private key file path (optional) | |
| username | Yes | SSH username |
Implementation Reference
- src/services/mcp-server.ts:185-218 (handler)Main handler for ssh_connect tool: validates input, creates SSHService with config, calls connect(), initializes dependent services on success, returns success message.private async handleSSHConnect( args: unknown ): Promise<{ content: Array<{ type: 'text'; text: string }> }> { const parsedConfig = SSHConfigSchema.parse(args); const config: SSHConfig = { host: parsedConfig.host, port: parsedConfig.port, username: parsedConfig.username, password: parsedConfig.password || undefined, privateKeyPath: parsedConfig.privateKeyPath || undefined, passphrase: parsedConfig.passphrase || undefined, }; this.sshService = new SSHService(config); const connected = await this.sshService.connect(); if (connected) { // Initialize other services this.vpsInitializer = new VPSInitializer(this.sshService); this.nginxManager = new NginxManager(this.sshService); this.githubCICD = new GitHubCICD(this.sshService); return { content: [ { type: 'text', text: `Successfully connected to ${config.host} as ${config.username}`, }, ], }; } else { throw new Error('Failed to establish SSH connection'); } }
- src/services/mcp-server.ts:17-24 (schema)Zod schema used to parse and validate the input arguments for the ssh_connect tool.const SSHConfigSchema = z.object({ host: z.string().describe('The IP address or hostname of the VPS'), port: z.number().optional().default(22).describe('SSH port (default: 22)'), username: z.string().describe('SSH username'), password: z.string().optional().describe('SSH password (if not using key)'), privateKeyPath: z.string().optional().describe('Path to private key file'), passphrase: z.string().optional().describe('Passphrase for private key'), });
- src/services/mcp-server.ts:74-88 (registration)Tool registration in the listTools response, defining name, description, and input schema.name: 'ssh_connect', description: 'Connect to a VPS via SSH using password or private key', inputSchema: { type: 'object', properties: { host: { type: 'string', description: 'VPS IP address or hostname' }, port: { type: 'number', description: 'SSH port (default: 22)' }, username: { type: 'string', description: 'SSH username' }, password: { type: 'string', description: 'SSH password (optional)' }, privateKeyPath: { type: 'string', description: 'Private key file path (optional)' }, passphrase: { type: 'string', description: 'Private key passphrase (optional)' }, }, required: ['host', 'username'], }, },
- src/services/ssh-service.ts:16-55 (helper)Core SSH connection logic in SSHService.connect(), using node-ssh library to establish connection with password or private key authentication.async connect(): Promise<boolean> { try { const connectionConfig: Parameters<NodeSSH['connect']>[0] = { host: this.config.host, port: this.config.port || 22, username: this.config.username, }; // Handle authentication methods if (this.config.privateKeyPath) { logger.info('Authenticating with private key', { keyPath: this.config.privateKeyPath, }); connectionConfig.privateKey = readFileSync(this.config.privateKeyPath, 'utf8'); if (this.config.passphrase) { connectionConfig.passphrase = this.config.passphrase; } } else if (this.config.password) { logger.info('Authenticating with password'); connectionConfig.password = this.config.password; } else { throw new Error('Either password or privateKeyPath must be provided'); } await this.ssh.connect(connectionConfig); this.isConnected = true; logger.info('Successfully connected to SSH server', { host: this.config.host, username: this.config.username, }); return true; } catch (error) { logger.error('Failed to connect to SSH server', { error: error instanceof Error ? error.message : 'Unknown error', host: this.config.host, }); this.isConnected = false; return false; } }