file_list
List files from a specified directory path. Provide a path to retrieve file names and subdirectories.
Instructions
List files from server
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Path to list files from |
Implementation Reference
- src/index.ts:94-96 (schema)Zod schema for the file_list tool input validation, defining an optional 'path' parameter.
const fileListSchema = z.object({ path: z.string().optional().describe("Path to list files from"), }); - src/index.ts:291-301 (registration)Registration of the 'file_list' tool in the tools array with name, description, and JSON input schema.
{ name: "file_list", description: "List files from server", schema: fileListSchema, inputSchema: { type: "object", properties: { path: { type: "string", description: "Path to list files from" } } } }, - src/index.ts:915-935 (handler)Handler implementation for the 'file_list' tool. It extracts the path argument, constructs CLI args calling 'coho file-list', executes via executeCohoCommand, and returns the result as text content.
case "file_list": { const { path } = args as FileListArgs; const fileArgs = [ 'file-list', '--project', config.projectId, '--space', config.space ]; if (path) fileArgs.push(path); const result = await executeCohoCommand(fileArgs); return { content: [ { type: "text", text: result } ], isError: false }; } - src/index.ts:529-564 (helper)Helper function executeCohoCommand that runs coho CLI commands with admin token, used by the file_list handler to invoke the coho file-list command.
async function executeCohoCommand(args: string[]): Promise<string> { const safeArgs = ['coho', ...args, '--admintoken', '***']; console.error(`Executing command: ${safeArgs.join(' ')}`); try { const { stdout, stderr } = await execFile('coho', [...args, '--admintoken', config.adminToken], { timeout: 120000 // 2 minutes timeout for CLI operations }); if (stderr) { // Sanitize stderr before logging to avoid token exposure const safeSterr = stderr.replace(new RegExp(config.adminToken, 'g'), '***'); console.error(`Command output to stderr:`, safeSterr); } console.error(`Command successful`); const result = stdout || stderr; // Sanitize result to ensure admin token is not exposed return result ? result.replace(new RegExp(config.adminToken, 'g'), '***') : result; } catch (error: any) { // Comprehensive sanitization of all error properties to avoid admin token exposure const sanitizeText = (text: string): string => text ? text.replace(new RegExp(config.adminToken, 'g'), '***') : text; const sanitizedMessage = sanitizeText(error?.message || 'Unknown error'); const sanitizedCmd = sanitizeText(error?.cmd || ''); const sanitizedStdout = sanitizeText(error?.stdout || ''); const sanitizedStderr = sanitizeText(error?.stderr || ''); // Log sanitized error details console.error(`Command failed: ${sanitizedMessage}`); if (sanitizedCmd) console.error(`Command: ${sanitizedCmd}`); if (sanitizedStdout) console.error(`Stdout: ${sanitizedStdout}`); if (sanitizedStderr) console.error(`Stderr: ${sanitizedStderr}`); // Return sanitized error message const errorDetails = [sanitizedMessage, sanitizedStderr].filter(Boolean).join(' - '); throw new McpError(ErrorCode.InvalidRequest, `Command failed: ${errorDetails}`); } }