Skip to main content
Glama

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
NameRequiredDescriptionDefault
connectionIdYesSSH connection ID

Implementation Reference

  • 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)}` ); } }
  • 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);

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