Skip to main content
Glama

terminal_list_dir

List directory contents across local systems, remote SSH servers, and GitHub repositories using the Global MCP Manager. Navigate and manage files efficiently in multi-environment contexts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dirNo.

Implementation Reference

  • Handler function implementing directory listing logic for both local filesystem (using fs.readdir and returning structured JSON) and SSH contexts (using ls command).
    async ({ dir }) => { try { if (globalConfig.context === 'ssh') { const command = `ls -la "${dir || globalConfig.ssh.appPath || '~'}"`; const result = await executeCommand(command); return { content: [{ type: 'text', text: result }], }; } else { const targetDir = dir || '.'; const files = await fs.readdir(targetDir, { withFileTypes: true }); const fileList = files.map(file => ({ name: file.name, isDirectory: file.isDirectory(), path: path.join(targetDir, file.name), })); return { content: [{ type: 'text', text: JSON.stringify(fileList, null, 2) }], }; } } catch (error) { return { content: [{ type: 'text', text: `Erro ao listar diretório: ${error.message}` }], }; } }
  • Zod schema for input parameters: 'dir' as optional string defaulting to current directory.
    { dir: z.string().default('.'), },
  • Registration of the 'terminal_list_dir' tool using server.tool(), specifying schema and handler within setupTerminalTools function.
    server.tool( 'terminal_list_dir', { dir: z.string().default('.'), }, async ({ dir }) => { try { if (globalConfig.context === 'ssh') { const command = `ls -la "${dir || globalConfig.ssh.appPath || '~'}"`; const result = await executeCommand(command); return { content: [{ type: 'text', text: result }], }; } else { const targetDir = dir || '.'; const files = await fs.readdir(targetDir, { withFileTypes: true }); const fileList = files.map(file => ({ name: file.name, isDirectory: file.isDirectory(), path: path.join(targetDir, file.name), })); return { content: [{ type: 'text', text: JSON.stringify(fileList, null, 2) }], }; } } catch (error) { return { content: [{ type: 'text', text: `Erro ao listar diretório: ${error.message}` }], }; } } );
  • Helper utility for executing shell commands, used by terminal_list_dir handler in SSH mode.
    // Função auxiliar para executar comandos async function executeCommand(command, cwd = null) { if (globalConfig.context === 'ssh') { if (!globalConfig.ssh.host || !globalConfig.ssh.username || !globalConfig.ssh.password) { throw new Error('Configuração SSH incompleta'); } const { stdout, stderr } = await execSSH( globalConfig.ssh.host, globalConfig.ssh.port, globalConfig.ssh.username, globalConfig.ssh.password, command ); return `${stdout}${stderr}`.trim(); } else { const { stdout, stderr } = await execPromise(command, { cwd: cwd || globalConfig.localWorkDir, }); return `${stdout}${stderr}`.trim(); } }

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/mamprimauto/mcp'

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