Skip to main content
Glama

ssh_upload_file

Upload a local file to a remote server via SSH connection by specifying local and remote paths.

Instructions

Upload a file to the remote server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesID of an active SSH connection
localPathYesPath to the local file
remotePathYesPath where the file should be saved on the remote server

Implementation Reference

  • The primary handler function that implements the ssh_upload_file tool. It validates the connection and local file, initializes an SFTP session over the SSH connection, and uploads the file using fastPut.
    private async handleSSHUpload(params: any) {
      const { connectionId, localPath, remotePath } = params;
      
      // Check if the connection exists
      if (!this.connections.has(connectionId)) {
        return {
          content: [{ type: "text", text: `No active SSH connection with ID: ${connectionId}` }],
          isError: true
        };
      }
      
      const { conn } = this.connections.get(connectionId)!;
      
      try {
        // Expand tilde if present in the local path
        const expandedLocalPath = localPath.replace(/^~/, os.homedir());
        
        // Check if the local file exists
        if (!fs.existsSync(expandedLocalPath)) {
          return {
            content: [{ type: "text", text: `Local file does not exist: ${expandedLocalPath}` }],
            isError: true
          };
        }
        
        // Get SFTP client
        const sftp: any = await new Promise((resolve, reject) => {
          conn.sftp((err: Error | undefined, sftp: any) => {
            if (err) {
              reject(new Error(`Failed to initialize SFTP: ${err.message}`));
            } else {
              resolve(sftp);
            }
          });
        });
        
        // Upload the file
        await new Promise((resolve, reject) => {
          sftp.fastPut(expandedLocalPath, remotePath, (err: Error | undefined) => {
            if (err) {
              reject(new Error(`Failed to upload file: ${err.message}`));
            } else {
              resolve(true);
            }
          });
        });
        
        return {
          content: [{ type: "text", text: `Successfully uploaded ${expandedLocalPath} to ${remotePath}` }]
        };
      } catch (error: any) {
        return {
          content: [{ type: "text", text: `File upload failed: ${error.message}` }],
          isError: true
        };
      }
    }
  • Input schema for ssh_upload_file tool defined in the server's capabilities declaration.
    ssh_upload_file: {
      description: "Upload a file to the remote server",
      inputSchema: {
        type: "object",
        properties: {
          connectionId: {
            type: "string",
            description: "ID of an active SSH connection"
          },
          localPath: {
            type: "string",
            description: "Path to the local file"
          },
          remotePath: {
            type: "string",
            description: "Path where the file should be saved on the remote server"
          }
        },
        required: ["connectionId", "localPath", "remotePath"]
      }
    },
  • src/index.ts:269-299 (registration)
    Registration of the tool call handler (CallToolRequestSchema), including the switch case that dispatches ssh_upload_file to its handler function.
    // Register tool call handler
    this.server.setRequestHandler(CallToolRequestSchema, async (request: any) => {
      const toolName = request.params.name;
      
      // Handle core SSH tools directly
      if (toolName.startsWith('ssh_')) {
        switch (toolName) {
          case 'ssh_connect':
            return this.handleSSHConnect(request.params.arguments);
          case 'ssh_exec':
            return this.handleSSHExec(request.params.arguments);
          case 'ssh_upload_file':
            return this.handleSSHUpload(request.params.arguments);
          case 'ssh_download_file':
            return this.handleSSHDownload(request.params.arguments);
          case 'ssh_list_files':
            return this.handleSSHListFiles(request.params.arguments);
          case 'ssh_disconnect':
            return this.handleSSHDisconnect(request.params.arguments);
          default:
            throw new Error(`Unknown SSH tool: ${toolName}`);
        }
      }
      
      // Handle Ubuntu tools directly
      if (toolName.startsWith('ubuntu_') && ubuntuToolHandlers[toolName]) {
        return ubuntuToolHandlers[toolName](request.params.arguments);
      }
      
      throw new Error(`Unknown tool: ${toolName}`);
    });
  • Duplicate input schema for ssh_upload_file in the ListToolsRequestSchema handler response.
    name: 'ssh_upload_file',
    description: 'Upload a file to the remote server',
    inputSchema: {
      type: 'object',
      properties: {
        connectionId: { type: 'string', description: 'ID of an active SSH connection' },
        localPath: { type: 'string', description: 'Path to the local file' },
        remotePath: { type: 'string', description: 'Path where the file should be saved on the remote server' }
      },
      required: ['connectionId', 'localPath', 'remotePath']
    }
  • Input schema for ssh_upload_file included in the overridden ListTools response from Ubuntu tools module.
      name: 'ssh_upload_file',
      description: 'Upload a file to the remote server',
      inputSchema: {
        type: 'object',
        properties: {
          connectionId: { type: 'string', description: 'ID of an active SSH connection' },
          localPath: { type: 'string', description: 'Path to the local file' },
          remotePath: { type: 'string', description: 'Path where the file should be saved on the remote server' }
        },
        required: ['connectionId', 'localPath', 'remotePath']
      }
    },
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 the action ('Upload') but lacks critical details: it doesn't specify whether this overwrites existing files, requires specific permissions, handles errors, or indicates success/failure. For a file transfer tool with zero annotation coverage, this leaves significant gaps in understanding its 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, direct sentence with zero wasted words. It front-loads the core action and resource efficiently, making it easy to parse quickly. Every word earns its place by conveying essential information without redundancy.

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 file operations and the lack of annotations or output schema, the description is insufficient. It doesn't cover behavioral aspects like error handling, success indicators, or interaction with sibling tools (e.g., dependency on 'ssh_connect'). For a tool that modifies remote systems, more context is needed to ensure safe and effective 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, clearly documenting all three required parameters. The description adds no additional semantic context beyond what the schema provides, such as file format constraints or path validation rules. Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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 action ('Upload') and target resource ('a file to the remote server'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling 'ssh_download_file' beyond the directional difference, missing an opportunity to clarify the upload-specific context.

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 like 'ssh_download_file' or 'ssh_list_files', nor does it mention prerequisites such as needing an active SSH connection via 'ssh_connect'. Without any contextual cues, users must infer usage from the tool name alone.

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/mixelpixx/SSH-MCP'

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