add_credential
Store a new SSH credential on the SSH MCP Server by specifying the host, username, and private key file path for secure remote command execution.
Instructions
Add a new SSH credential with private key file path
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | Yes | ||
| name | Yes | ||
| privateKeyPath | Yes | ||
| username | Yes |
Implementation Reference
- src/index.ts:205-236 (handler)The main handler function for the 'add_credential' tool. It extracts arguments, validates the private key path, inserts the credential into the SQLite database, and returns success or error response.case 'add_credential': { const { name, host, username, privateKeyPath } = request.params.arguments as { name: string; host: string; username: string; privateKeyPath: string; }; try { const validatedKeyPath = validatePrivateKeyPath(privateKeyPath); await db.run( 'INSERT INTO credentials (name, host, username, privateKeyPath) VALUES (?, ?, ?, ?)', [name, host, username, validatedKeyPath] ); return { content: [{ type: 'text', text: `Credential ${name} added successfully` }] }; } catch (error: unknown) { return { content: [{ type: 'text', text: `Error: ${error instanceof Error ? error.message : String(error)}`, }], isError: true, }; } }
- src/index.ts:97-110 (registration)Registration of the 'add_credential' tool in the ListToolsRequestSchema handler, including name, description, and input schema definition.{ name: 'add_credential', description: 'Add a new SSH credential with private key file path', inputSchema: { type: 'object', properties: { name: { type: 'string' }, host: { type: 'string' }, username: { type: 'string' }, privateKeyPath: { type: 'string' }, }, required: ['name', 'host', 'username', 'privateKeyPath'], }, },
- src/index.ts:100-109 (schema)Input schema definition for the 'add_credential' tool, specifying required parameters: name, host, username, privateKeyPath.inputSchema: { type: 'object', properties: { name: { type: 'string' }, host: { type: 'string' }, username: { type: 'string' }, privateKeyPath: { type: 'string' }, }, required: ['name', 'host', 'username', 'privateKeyPath'], },
- src/index.ts:49-60 (helper)Helper function to validate and resolve the private key file path, ensuring it exists, called within the add_credential handler.function validatePrivateKeyPath(path: string): string { console.error('DEBUG: Validating key path input:', path); // Log input if (typeof path !== 'string') { throw new Error('validatePrivateKeyPath received non-string input'); } const resolvedPath = resolve(path); console.error('DEBUG: Resolved key path:', resolvedPath); // Log resolved if (!existsSync(resolvedPath)) { throw new Error(`Private key file not found at path: ${resolvedPath}`); } return resolvedPath; }