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
| Name | Required | Description | Default |
|---|---|---|---|
| dir | No | . |
Implementation Reference
- terminal-service.js:99-126 (handler)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}` }], }; } }
- terminal-service.js:96-98 (schema)Zod schema for input parameters: 'dir' as optional string defaulting to current directory.{ dir: z.string().default('.'), },
- terminal-service.js:94-127 (registration)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}` }], }; } } );
- terminal-service.js:47-70 (helper)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(); } }