Skip to main content
Glama

listFiles

Retrieve a list of files from a specified directory to manage project files efficiently in Expo-based React Native development environments.

Instructions

List files in a directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directoryPathYesThe path to the directory to list files from

Implementation Reference

  • The main handler function implementing the listFiles tool. Normalizes the directory path, lists files and directories using fs.promises.readdir, constructs a list with name, isDirectory, and full path for each entry, and returns a JSON-formatted text response. Includes logging and error handling.
    export async function listFiles(args: { directoryPath: string }, { log }: LogContext) { try { log.info(`Listing files in directory: ${args.directoryPath}`); const normalizedPath = path.normalize(args.directoryPath); const files = await fs.promises.readdir(normalizedPath, { withFileTypes: true }); const fileList = files.map((file) => ({ name: file.name, isDirectory: file.isDirectory(), path: path.join(normalizedPath, file.name), })); log.info( `Successfully listed ${fileList.length} files in ${normalizedPath}`, ); return { content: [ { type: "text", text: JSON.stringify(fileList, null, 2), }, ], }; } catch (error: any) { log.error(`Error listing files: ${error.message}`); throw new Error(`Failed to list files: ${error.message}`); } }
  • src/index.ts:37-46 (registration)
    Registration of the listFiles tool on the FastMCP server using addTool. Includes the tool name, description, Zod input schema for directoryPath parameter, and assignment of the handler function to execute.
    addTool({ name: "listFiles", description: "List files in a directory", parameters: z.object({ directoryPath: z .string() .describe("The path to the directory to list files from"), }), execute: listFiles, });
  • Zod schema defining the input parameters for the listFiles tool: a single required string parameter directoryPath with description.
    parameters: z.object({ directoryPath: z .string() .describe("The path to the directory to list files from"), }),

Other Tools

Related 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/mattlemmone/expo-mcp'

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