ssh_save_credential
Save SSH credentials with a unique ID for secure reuse in remote server connections, supporting both password and SSH key authentication.
Instructions
Save SSH credentials for reuse
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| credentialId | Yes | Unique identifier for this credential | |
| host | Yes | SSH server hostname or IP address | |
| passphrase | No | Passphrase for private key | |
| password | No | SSH password (if not using key) | |
| port | No | SSH port number | |
| privateKeyPath | No | Path to private key file | |
| username | Yes | SSH username |
Input Schema (JSON Schema)
{
"properties": {
"credentialId": {
"description": "Unique identifier for this credential",
"type": "string"
},
"host": {
"description": "SSH server hostname or IP address",
"type": "string"
},
"passphrase": {
"description": "Passphrase for private key",
"type": "string"
},
"password": {
"description": "SSH password (if not using key)",
"type": "string"
},
"port": {
"default": 22,
"description": "SSH port number",
"type": "number"
},
"privateKeyPath": {
"description": "Path to private key file",
"type": "string"
},
"username": {
"description": "SSH username",
"type": "string"
}
},
"required": [
"credentialId",
"host",
"username"
],
"type": "object"
}
Implementation Reference
- src/index.ts:1087-1125 (handler)The handler function that parses input parameters using SaveCredentialSchema, validates uniqueness and auth method, stores the credential in the in-memory credentialStore map, and returns success message.private async handleSaveCredential(args: unknown) { const params = SaveCredentialSchema.parse(args); if (credentialStore.has(params.credentialId)) { throw new McpError( ErrorCode.InvalidParams, `Credential ID '${params.credentialId}' already exists` ); } if (!params.password && !params.privateKeyPath) { throw new McpError( ErrorCode.InvalidParams, 'Either password or privateKeyPath must be provided' ); } const credential: StoredCredential = { host: params.host, port: params.port || 22, username: params.username, password: params.password, privateKeyPath: params.privateKeyPath, passphrase: params.passphrase, createdAt: new Date().toISOString(), lastUsed: new Date().toISOString() }; credentialStore.set(params.credentialId, credential); return { content: [ { type: 'text', text: `Credential '${params.credentialId}' saved successfully for ${params.username}@${params.host}:${params.port || 22}`, }, ], }; }
- src/index.ts:123-131 (schema)Zod schema defining the input parameters for the ssh_save_credential tool, including credentialId, host, port, username, and optional auth fields.const SaveCredentialSchema = z.object({ credentialId: z.string().describe('Unique identifier for this credential'), host: z.string().describe('SSH server hostname or IP address'), port: z.number().default(22).describe('SSH port number'), 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/index.ts:371-386 (registration)Registration of the ssh_save_credential tool in the ListTools response, including name, description, and input schema matching the Zod schema.{ name: 'ssh_save_credential', description: 'Save SSH credentials for reuse', inputSchema: { type: 'object', properties: { credentialId: { type: 'string', description: 'Unique identifier for this credential' }, host: { type: 'string', description: 'SSH server hostname or IP address' }, port: { type: 'number', default: 22, description: 'SSH port number' }, username: { type: 'string', description: 'SSH username' }, password: { type: 'string', description: 'SSH password (if not using key)' }, privateKeyPath: { type: 'string', description: 'Path to private key file' }, passphrase: { type: 'string', description: 'Passphrase for private key' } }, required: ['credentialId', 'host', 'username'] },
- src/index.ts:505-506 (registration)Dispatch to the handleSaveCredential handler in the CallToolRequest switch statement.case 'ssh_save_credential': return await this.handleSaveCredential(args);
- src/index.ts:34-43 (helper)TypeScript interface defining the structure of stored SSH credentials used by the handler.interface StoredCredential { host: string; port: number; username: string; password?: string; privateKeyPath?: string; passphrase?: string; createdAt: string; lastUsed: string; }