ssh_set_working_directory
Set the current working directory for an SSH connection using the provided connection ID and directory path, enabling efficient navigation and operations on remote systems via SSH MCP Server.
Instructions
Set the current working directory for a connection
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connectionId | Yes | SSH connection ID | |
| workingDirectory | Yes | Working directory path to set as current |
Input Schema (JSON Schema)
{
"properties": {
"connectionId": {
"description": "SSH connection ID",
"type": "string"
},
"workingDirectory": {
"description": "Working directory path to set as current",
"type": "string"
}
},
"required": [
"connectionId",
"workingDirectory"
],
"type": "object"
}
Implementation Reference
- src/index.ts:1250-1291 (handler)The handler function for 'ssh_set_working_directory' tool. Parses input with SetWorkingDirectorySchema, verifies the directory exists via SSH command, updates the connection context's currentWorkingDirectory, and returns a success message.private async handleSetWorkingDirectory(args: unknown) { const params = SetWorkingDirectorySchema.parse(args); const context = connectionContexts.get(params.connectionId); if (!context) { throw new McpError( ErrorCode.InvalidParams, `Connection ID '${params.connectionId}' not found` ); } try { // Verify the directory exists const result = await context.ssh.execCommand(`test -d "${params.workingDirectory}" && echo "exists"`); if (result.code !== 0) { throw new McpError( ErrorCode.InvalidParams, `Directory '${params.workingDirectory}' does not exist or is not accessible` ); } // Set the working directory context.currentWorkingDirectory = params.workingDirectory; return { content: [ { type: 'text', text: `Working directory set to: ${params.workingDirectory}`, }, ], }; } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Failed to set working directory: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:148-151 (schema)Zod schema defining the input parameters: connectionId (string) and workingDirectory (string). Used for validation in the handler.const SetWorkingDirectorySchema = z.object({ connectionId: z.string().describe('SSH connection ID'), workingDirectory: z.string().describe('Working directory path to set as current') });
- src/index.ts:421-431 (registration)Tool registration in the ListTools response, defining name, description, and inputSchema matching the handler's expectations.name: 'ssh_set_working_directory', description: 'Set the current working directory for a connection', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'SSH connection ID' }, workingDirectory: { type: 'string', description: 'Working directory path to set as current' } }, required: ['connectionId', 'workingDirectory'] }, },
- src/index.ts:513-514 (registration)Dispatch case in the CallToolRequest handler switch statement that routes the tool call to the specific handler method.case 'ssh_set_working_directory': return await this.handleSetWorkingDirectory(args);