Skip to main content
Glama

ssh_connect_with_credential

Establish SSH connections using pre-saved credentials to securely access remote servers for file transfers, shell sessions, and Docker management without manual authentication.

Instructions

Connect to SSH server using saved credentials

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesUnique identifier for this connection
credentialIdYesStored credential ID to use

Implementation Reference

  • Main handler function for 'ssh_connect_with_credential' tool. Parses arguments using ConnectWithCredentialSchema, retrieves stored credential, connects via NodeSSH, stores connection in pool and context, updates credential last used time, returns success message.
    private async handleConnectWithCredential(args: unknown) { const params = ConnectWithCredentialSchema.parse(args); if (connectionPool.has(params.connectionId)) { throw new McpError( ErrorCode.InvalidParams, `Connection ID '${params.connectionId}' already exists` ); } const credential = credentialStore.get(params.credentialId); if (!credential) { throw new McpError( ErrorCode.InvalidParams, `Credential ID '${params.credentialId}' not found` ); } const ssh = new NodeSSH(); try { const connectConfig: any = { host: credential.host, port: credential.port, username: credential.username, }; if (credential.privateKeyPath) { const privateKey = await fs.readFile(credential.privateKeyPath, 'utf8'); connectConfig.privateKey = privateKey; if (credential.passphrase) { connectConfig.passphrase = credential.passphrase; } } else if (credential.password) { connectConfig.password = credential.password; } else { throw new McpError( ErrorCode.InvalidParams, 'Credential has neither password nor private key' ); } await ssh.connect(connectConfig); connectionPool.set(params.connectionId, ssh); // Initialize connection context connectionContexts.set(params.connectionId, { ssh, currentWorkingDirectory: undefined, defaultWorkingDirectory: undefined }); // Update last used timestamp credential.lastUsed = new Date().toISOString(); credentialStore.set(params.credentialId, credential); return { content: [ { type: 'text', text: `Successfully connected to ${credential.host}:${credential.port} as ${credential.username} using saved credential '${params.credentialId}' (Connection ID: ${params.connectionId})`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `SSH connection failed: ${error instanceof Error ? error.message : String(error)}` ); }
  • Zod schema defining input parameters for ssh_connect_with_credential: credentialId (required string) and connectionId (required string). Used for validation in handler.
    const ConnectWithCredentialSchema = z.object({ credentialId: z.string().describe('Stored credential ID to use'), connectionId: z.string().describe('Unique identifier for this connection') });
  • src/index.ts:480-536 (registration)
    Tool dispatch in CallToolRequest handler: switch case routes 'ssh_connect_with_credential' calls to handleConnectWithCredential.
    this.server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest) => { try { const { name, arguments: args } = request.params; switch (name) { case 'ssh_connect': return await this.handleSSHConnect(args); case 'ssh_disconnect': return await this.handleSSHDisconnect(args); case 'ssh_execute': return await this.handleSSHExecute(args); case 'ssh_copy_file': return await this.handleSSHCopyFile(args); case 'ssh_list_files': return await this.handleSSHListFiles(args); case 'ssh_file_info': return await this.handleSSHFileInfo(args); case 'ssh_start_interactive_shell': return await this.handleStartInteractiveShell(args); case 'ssh_send_input': return await this.handleSendInput(args); case 'ssh_read_output': return await this.handleReadOutput(args); case 'ssh_close_interactive_shell': return await this.handleCloseInteractiveShell(args); case 'ssh_save_credential': return await this.handleSaveCredential(args); case 'ssh_list_credentials': return await this.handleListCredentials(args); case 'ssh_delete_credential': return await this.handleDeleteCredential(args); case 'ssh_connect_with_credential': return await this.handleConnectWithCredential(args); case 'ssh_set_working_directory': return await this.handleSetWorkingDirectory(args); case 'ssh_get_working_directory': return await this.handleGetWorkingDirectory(args); case 'ssh_docker_deploy': return await this.handleDockerDeploy(args); case 'ssh_docker_status': return await this.handleDockerStatus(args); default: throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${name}` ); } } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : String(error)}` ); } });
  • src/index.ts:408-418 (registration)
    Tool metadata registration in ListTools response: name, description, and inputSchema definition.
    { name: 'ssh_connect_with_credential', description: 'Connect to SSH server using saved credentials', inputSchema: { type: 'object', properties: { credentialId: { type: 'string', description: 'Stored credential ID to use' }, connectionId: { type: 'string', description: 'Unique identifier for this connection' } }, required: ['credentialId', 'connectionId'] },
  • Zod input validation schema for the tool.
    const ConnectWithCredentialSchema = z.object({ credentialId: z.string().describe('Stored credential ID to use'), connectionId: z.string().describe('Unique identifier for this connection') });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mahathirmuh/mcp-ssh-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server