Skip to main content
Glama
widjis
by widjis

ssh_copy_file

Copy files between local and remote servers or between remote servers using SSH connections. Specify source and target paths with connection IDs to transfer files across systems.

Instructions

Copy files between local and remote servers or between remote servers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceConnectionIdYesSource SSH connection ID (use "local" for local files)
sourcePathYesSource file path
targetConnectionIdYesTarget SSH connection ID (use "local" for local files)
targetPathYesTarget file path
createDirectoriesNoCreate target directories if they don't exist

Implementation Reference

  • Main handler function for 'ssh_copy_file' tool. Parses input using CopyFileSchema, handles four copy scenarios: local-to-local (fs.copyFile), local-to-remote (putFile), remote-to-local (getFile), remote-to-remote (getFile to temp then putFile), creates directories if needed, returns success message.
    private async handleSSHCopyFile(args: unknown) {
      const params = CopyFileSchema.parse(args);
      
      try {
        // Handle different copy scenarios
        if (params.sourceConnectionId === 'local' && params.targetConnectionId === 'local') {
          // Local to local copy
          await fs.copyFile(params.sourcePath, params.targetPath);
          return {
            content: [
              {
                type: 'text',
                text: `Successfully copied ${params.sourcePath} to ${params.targetPath} (local to local)`,
              },
            ],
          };
        } else if (params.sourceConnectionId === 'local') {
          // Local to remote
          const targetSSH = connectionPool.get(params.targetConnectionId);
          if (!targetSSH) {
            throw new McpError(
              ErrorCode.InvalidParams,
              `Target connection ID '${params.targetConnectionId}' not found`
            );
          }
    
          if (params.createDirectories) {
            const targetDir = path.dirname(params.targetPath);
            await targetSSH.execCommand(`mkdir -p "${targetDir}"`);
          }
    
          await targetSSH.putFile(params.sourcePath, params.targetPath);
          return {
            content: [
              {
                type: 'text',
                text: `Successfully copied ${params.sourcePath} to ${params.targetConnectionId}:${params.targetPath}`,
              },
            ],
          };
        } else if (params.targetConnectionId === 'local') {
          // Remote to local
          const sourceSSH = connectionPool.get(params.sourceConnectionId);
          if (!sourceSSH) {
            throw new McpError(
              ErrorCode.InvalidParams,
              `Source connection ID '${params.sourceConnectionId}' not found`
            );
          }
    
          if (params.createDirectories) {
            const targetDir = path.dirname(params.targetPath);
            await fs.mkdir(targetDir, { recursive: true });
          }
    
          await sourceSSH.getFile(params.targetPath, params.sourcePath);
          return {
            content: [
              {
                type: 'text',
                text: `Successfully copied ${params.sourceConnectionId}:${params.sourcePath} to ${params.targetPath}`,
              },
            ],
          };
        } else {
          // Remote to remote
          const sourceSSH = connectionPool.get(params.sourceConnectionId);
          const targetSSH = connectionPool.get(params.targetConnectionId);
          
          if (!sourceSSH) {
            throw new McpError(
              ErrorCode.InvalidParams,
              `Source connection ID '${params.sourceConnectionId}' not found`
            );
          }
          if (!targetSSH) {
            throw new McpError(
              ErrorCode.InvalidParams,
              `Target connection ID '${params.targetConnectionId}' not found`
            );
          }
    
          // Use a temporary local file for remote-to-remote transfer
          const tempFile = `/tmp/mcp-ssh-temp-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
          
          try {
            await sourceSSH.getFile(tempFile, params.sourcePath);
            
            if (params.createDirectories) {
              const targetDir = path.dirname(params.targetPath);
              await targetSSH.execCommand(`mkdir -p "${targetDir}"`);
            }
            
            await targetSSH.putFile(tempFile, params.targetPath);
            await fs.unlink(tempFile); // Clean up temp file
            
            return {
              content: [
                {
                  type: 'text',
                  text: `Successfully copied ${params.sourceConnectionId}:${params.sourcePath} to ${params.targetConnectionId}:${params.targetPath}`,
                },
              ],
            };
          } catch (error) {
            // Clean up temp file on error
            try {
              await fs.unlink(tempFile);
            } catch {}
            throw error;
          }
        }
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `File copy failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Zod schema for validating input parameters of the ssh_copy_file tool.
    const CopyFileSchema = z.object({
      sourceConnectionId: z.string().describe('Source SSH connection ID (use "local" for local files)'),
      sourcePath: z.string().describe('Source file path'),
      targetConnectionId: z.string().describe('Target SSH connection ID (use "local" for local files)'),
      targetPath: z.string().describe('Target file path'),
      createDirectories: z.boolean().default(true).describe('Create target directories if they don\'t exist')
    });
  • src/index.ts:279-293 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema for ssh_copy_file.
    {
      name: 'ssh_copy_file',
      description: 'Copy files between local and remote servers or between remote servers',
      inputSchema: {
        type: 'object',
        properties: {
          sourceConnectionId: { type: 'string', description: 'Source SSH connection ID (use "local" for local files)' },
          sourcePath: { type: 'string', description: 'Source file path' },
          targetConnectionId: { type: 'string', description: 'Target SSH connection ID (use "local" for local files)' },
          targetPath: { type: 'string', description: 'Target file path' },
          createDirectories: { type: 'boolean', default: true, description: 'Create target directories if they don\'t exist' }
        },
        required: ['sourceConnectionId', 'sourcePath', 'targetConnectionId', 'targetPath']
      },
    },
  • src/index.ts:491-492 (registration)
    Switch case in CallToolRequest handler that routes 'ssh_copy_file' calls to the handleSSHCopyFile method.
    case 'ssh_copy_file':
      return await this.handleSSHCopyFile(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 the action 'copy files' but doesn't mention critical behaviors: whether it overwrites existing files, handles permissions, supports recursive copying, provides progress feedback, or has rate limits. This is inadequate for a file operation tool.

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 with zero wasted words. It's front-loaded with the core purpose and avoids unnecessary elaboration, making it easy to parse quickly.

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?

For a file copy operation with no annotations and no output schema, the description is incomplete. It lacks behavioral details (overwrite behavior, error handling), usage context (prerequisites like active connections), and output expectations. This leaves significant gaps for an agent to use the tool correctly.

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?

Schema description coverage is 100%, so the schema fully documents all 5 parameters. The description adds no additional parameter semantics beyond implying directionality (local/remote), which is already covered by parameter descriptions. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose5/5

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

The description clearly states the verb 'copy' and the resource 'files', specifying the directionality 'between local and remote servers or between remote servers'. This distinguishes it from sibling tools like ssh_list_files (list) or ssh_execute (execute commands).

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. It doesn't mention prerequisites (e.g., needing established SSH connections), exclusions, or comparisons to similar tools like ssh_file_info for checking file existence before copying.

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/widjis/mcp-ssh'

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