Skip to main content
Glama

ssh_list_files

List files and directories on local or remote servers via SSH connections. Specify a directory path to view its contents, with options to include hidden files.

Instructions

List files and directories on local or remote server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesSSH connection ID (use "local" for local files)
remotePathYesDirectory path to list
showHiddenNoShow hidden files

Implementation Reference

  • Main handler function that executes the ssh_list_files tool: lists files locally with fs.readdir (filtering hidden if not specified) or remotely via SSH 'ls -l(a)' command.
    private async handleSSHListFiles(args: unknown) { const params = ListFilesSchema.parse(args); try { if (params.connectionId === 'local') { // List local files const files = await fs.readdir(params.remotePath, { withFileTypes: true }); const fileList = files .filter((file) => params.showHidden || !file.name.startsWith('.')) .map((file) => ({ name: file.name, type: file.isDirectory() ? 'directory' : 'file', path: path.join(params.remotePath, file.name) })); return { content: [ { type: 'text', text: `Files in ${params.remotePath}:\n${JSON.stringify(fileList, null, 2)}`, }, ], }; } else { // List remote files const ssh = connectionPool.get(params.connectionId); if (!ssh) { throw new McpError( ErrorCode.InvalidParams, `Connection ID '${params.connectionId}' not found` ); } const lsCommand = params.showHidden ? 'ls -la' : 'ls -l'; const result = await ssh.execCommand(`${lsCommand} "${params.remotePath}"`); if (result.code !== 0) { throw new Error(`ls command failed: ${result.stderr}`); } return { content: [ { type: 'text', text: `Files in ${params.connectionId}:${params.remotePath}:\n${result.stdout}`, }, ], }; } } catch (error) { throw new McpError( ErrorCode.InternalError, `List files failed: ${error instanceof Error ? error.message : String(error)}` ); } }
  • Zod schema used to parse and validate input arguments for the ssh_list_files tool.
    const ListFilesSchema = z.object({ connectionId: z.string().describe('SSH connection ID (use "local" for local files)'), remotePath: z.string().describe('Directory path to list'), showHidden: z.boolean().default(false).describe('Show hidden files') });
  • src/index.ts:295-306 (registration)
    Tool definition registered in the ListTools response, specifying name, description, and input schema.
    name: 'ssh_list_files', description: 'List files and directories on local or remote server', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'SSH connection ID (use "local" for local files)' }, remotePath: { type: 'string', description: 'Directory path to list' }, showHidden: { type: 'boolean', default: false, description: 'Show hidden files' } }, required: ['connectionId', 'remotePath'] }, },
  • src/index.ts:493-495 (registration)
    Dispatch in CallToolRequest handler switch statement that routes to the tool's handler function.
    case 'ssh_list_files': return await this.handleSSHListFiles(args); case 'ssh_file_info':

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