Skip to main content
Glama

ssh_get_working_directory

Retrieve the current working directory path for an active SSH connection to help users track their location on remote servers during file operations and navigation.

Instructions

Get the current working directory for a connection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesSSH connection ID

Implementation Reference

  • The handler function that executes the ssh_get_working_directory tool. It parses input using GetWorkingDirectorySchema, retrieves the SSH connection context, and either returns the cached current working directory or executes the 'pwd' command remotely to fetch and cache it.
    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)}` ); }
  • Zod schema defining the input parameters for the ssh_get_working_directory tool, requiring a connectionId.
    const GetWorkingDirectorySchema = z.object({ connectionId: z.string().describe('SSH connection ID') });
  • src/index.ts:432-442 (registration)
    Registration of the ssh_get_working_directory tool in the list returned by the ListToolsRequestSchema handler, including 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 CallToolRequestSchema handler that routes calls to ssh_get_working_directory to its handler function.
    case 'ssh_get_working_directory': return await this.handleGetWorkingDirectory(args);

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