Skip to main content
Glama
ai-yliu

Filesystem MCP Server

by ai-yliu

list_directory

Retrieve contents of a specified directory by providing its path. Lists files and directories with [FILE] or [DIR] prefixes for clear identification.

Instructions

List directory contents with [FILE] or [DIR] prefixes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the directory to list

Implementation Reference

  • The main handler logic for the 'list_directory' tool. It extracts the directory path from arguments, validates access, reads directory entries, asynchronously stats each entry to determine if it's a file or directory, formats each with [DIR] or [FILE] prefix, joins them with newlines, and returns as text content.
    case 'list_directory': { const { path: dirPath } = request.params.arguments as { path: string }; validatePath(dirPath); const entries = await fs.readdir(dirPath); const formattedEntries = await Promise.all( entries.map(async (entry) => { const entryPath = path.join(dirPath, entry); const stats = await fs.stat(entryPath); const prefix = stats.isDirectory() ? '[DIR]' : '[FILE]'; return `${prefix} ${entry}`; }) ); return { content: [ { type: 'text', text: formattedEntries.join('\n'), }, ], }; }
  • src/index.ts:158-171 (registration)
    Registration of the 'list_directory' tool in the ListTools response, including its name, description, and input schema definition.
    { name: 'list_directory', description: 'List directory contents with [FILE] or [DIR] prefixes', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the directory to list', }, }, required: ['path'], }, },
  • Input schema definition for the 'list_directory' tool, specifying the required 'path' parameter.
    inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the directory to list', }, }, required: ['path'], },

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/ai-yliu/filesystem-mcp-server'

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