Skip to main content
Glama

ssh_get_working_directory

Retrieve the current working directory path for an active SSH connection to remote servers.

Instructions

Get the current working directory for a connection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesSSH connection ID

Implementation Reference

  • The main handler function for the 'ssh_get_working_directory' tool. It parses input using GetWorkingDirectorySchema, retrieves the connection context, checks the cached currentWorkingDirectory, falls back to executing 'pwd' command via SSH if not cached, caches the result, 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)}` ); }
  • Zod schema defining the input parameters for the ssh_get_working_directory tool: requires 'connectionId' string.
    const GetWorkingDirectorySchema = z.object({ connectionId: z.string().describe('SSH connection ID') });
  • src/index.ts:432-442 (registration)
    Tool registration entry in the ListTools handler, specifying the tool name, description, and input schema matching GetWorkingDirectorySchema.
    { 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 switch statement that routes calls to the handleGetWorkingDirectory method.
    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