Skip to main content
Glama

ssh_get_working_directory

Retrieve the current working directory path for an active SSH connection to navigate remote file systems efficiently.

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 the schema, retrieves the connection context, fetches the current working directory either from cache or by running 'pwd' remotely, caches it, and returns the result.
    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 a connectionId string.
    const GetWorkingDirectorySchema = z.object({ connectionId: z.string().describe('SSH connection ID') });
  • src/index.ts:432-441 (registration)
    Registration of the ssh_get_working_directory tool in the ListTools response, including its name, description, and input schema definition.
    { 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:517-518 (registration)
    Dispatch case in the CallToolRequest handler that routes calls to ssh_get_working_directory to its handler function.
    case 'ssh_docker_deploy': return await this.handleDockerDeploy(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/widjis/mcp-ssh'

If you have feedback or need assistance with the MCP directory API, please join our Discord server