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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't add context beyond that—for example, it doesn't mention if this is a read-only operation, what permissions are required, how it handles errors, or what the output format might be. This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without any wasted words. It's appropriately sized and front-loaded, making it easy to understand at a glance.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of SSH operations and the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., a string path), potential errors, or dependencies like requiring an active connection, leaving the agent with insufficient context for reliable use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the single parameter 'connectionId' clearly documented. The description doesn't add any extra meaning or details about the parameter beyond what the schema provides, so it meets the baseline of 3 for adequate but not enhanced parameter semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and the resource 'current working directory for a connection', making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'ssh_set_working_directory' beyond the obvious 'get' vs 'set' distinction, which is why it doesn't earn a perfect 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, such as when to prefer this over other directory-related operations or in what context it's most useful. It lacks any mention of prerequisites, exclusions, or related tools, leaving usage entirely implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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