Skip to main content
Glama
akshat12000

File System Explorer MCP Server

by akshat12000

list_directory

Lists the contents of a specified directory path to view files and subdirectories within a file system.

Instructions

List the contents of a directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe directory path to list

Implementation Reference

  • Zod schema for validating input arguments to the list_directory tool.
    const ListDirectoryArgsSchema = z.object({ path: z.string().describe("The directory path to list") });
  • src/index.ts:144-157 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining name, description, and JSON input schema.
    { name: "list_directory", description: "List the contents of a directory", inputSchema: { type: "object", properties: { path: { type: "string", description: "The directory path to list" } }, required: ["path"] } },
  • Main handler logic for the list_directory tool: validates input, reads directory, gets stats for each entry, formats output with icons, sizes, and modification times.
    case "list_directory": { const { path: dirPath } = ListDirectoryArgsSchema.parse(args); const safePath = validatePath(dirPath); const entries = await fs.readdir(safePath, { withFileTypes: true }); const items = await Promise.all( entries.map(async (entry) => { const fullPath = path.join(safePath, entry.name); try { const stats = await fs.stat(fullPath); return { name: entry.name, type: entry.isDirectory() ? 'directory' : 'file', size: entry.isFile() ? formatFileSize(stats.size) : null, modified: stats.mtime.toISOString() }; } catch (error) { return { name: entry.name, type: entry.isDirectory() ? 'directory' : 'file', size: null, modified: null, error: 'Unable to read stats' }; } }) ); return { content: [ { type: "text", text: `Directory listing for: ${safePath}\n\n` + items .sort((a, b) => { // Sort directories first, then files if (a.type !== b.type) { return a.type === 'directory' ? -1 : 1; } return a.name.localeCompare(b.name); }) .map(item => { const icon = item.type === 'directory' ? 'πŸ“' : 'πŸ“„'; const size = item.size ? ` (${item.size})` : ''; const modified = item.modified ? ` - Modified: ${new Date(item.modified).toLocaleString()}` : ''; return `${icon} ${item.name}${size}${modified}`; }) .join('\n') } ] }; }

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/akshat12000/FileSystem-MCPServer'

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