ssh_get_working_directory
Retrieve the current working directory for an active SSH connection on SSH MCP Server using the connection ID. Simplify remote directory tracking and management.
Instructions
Get the current working directory for a connection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connectionId | Yes | SSH connection ID |
Implementation Reference
- src/index.ts:1293-1338 (handler)The handler function that executes the tool logic. It parses input, retrieves the connection context, gets the current working directory from cache or by running 'pwd' command on the remote SSH server, caches it, and returns the directory path.private async handleGetWorkingDirectory(args: unknown) { const params = GetWorkingDirectorySchema.parse(args); const context = connectionContexts.get(params.connectionId); if (!context) { throw new McpError( ErrorCode.InvalidParams, `Connection ID '${params.connectionId}' not found` ); } try { let currentDir = context.currentWorkingDirectory; if (!currentDir) { // Get current directory from remote system const result = await context.ssh.execCommand('pwd'); if (result.code === 0) { currentDir = result.stdout.trim(); context.currentWorkingDirectory = currentDir; } else { throw new McpError( ErrorCode.InternalError, `Failed to get current directory: ${result.stderr}` ); } } return { content: [ { type: 'text', text: `Current working directory: ${currentDir}`, }, ], }; } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Failed to get working directory: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:153-155 (schema)Zod schema defining the input parameters for the tool: requires 'connectionId'.const GetWorkingDirectorySchema = z.object({ connectionId: z.string().describe('SSH connection ID') });
- src/index.ts:433-442 (registration)Tool registration entry in the listTools response, specifying the tool name, description, and input schema.name: 'ssh_get_working_directory', description: 'Get the current working directory for a connection', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'SSH connection ID' } }, required: ['connectionId'] }, },
- src/index.ts:515-516 (registration)Dispatch case in the CallToolRequest handler that routes calls to ssh_get_working_directory to its handler function.case 'ssh_get_working_directory': return await this.handleGetWorkingDirectory(args);