Skip to main content
Glama
zad0xlik

RateSpot MCP Server

by zad0xlik

list-directory

Retrieve directory contents by specifying a path; optionally list files recursively. Use this tool to efficiently manage and access directory structures on the RateSpot MCP Server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the directory to list
recursiveNoWhether to list files recursively

Implementation Reference

  • The handler function for the 'list-directory' tool. It reads the directory using fs.readdirSync, handles recursion if specified, uses FileAnalyzer.getFileInfo for each file, and returns a JSON array of file information.
    async (params) => { try { const files: ReturnType<typeof FileAnalyzer.getFileInfo>[] = []; const listFiles = (dir: string) => { const entries = fs.readdirSync(dir); for (const entry of entries) { const fullPath = path.join(dir, entry); const stats = fs.statSync(fullPath); if (stats.isFile()) { files.push(FileAnalyzer.getFileInfo(fullPath)); } else if (stats.isDirectory() && params.recursive) { listFiles(fullPath); } } }; listFiles(params.path); const fileInfos = files; return { content: [{ type: "text", text: JSON.stringify(fileInfos, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error listing directory: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • Zod input schema defining 'path' (required string) and 'recursive' (optional boolean, default false) parameters for the list-directory tool.
    { path: z.string().describe("Path to the directory to list"), recursive: z.boolean().optional().default(false).describe("Whether to list files recursively") },
  • MCP server tool registration call for 'list-directory', including name, schema, and handler reference.
    server.tool( "list-directory", { path: z.string().describe("Path to the directory to list"), recursive: z.boolean().optional().default(false).describe("Whether to list files recursively") }, async (params) => { try { const files: ReturnType<typeof FileAnalyzer.getFileInfo>[] = []; const listFiles = (dir: string) => { const entries = fs.readdirSync(dir); for (const entry of entries) { const fullPath = path.join(dir, entry); const stats = fs.statSync(fullPath); if (stats.isFile()) { files.push(FileAnalyzer.getFileInfo(fullPath)); } else if (stats.isDirectory() && params.recursive) { listFiles(fullPath); } } }; listFiles(params.path); const fileInfos = files; return { content: [{ type: "text", text: JSON.stringify(fileInfos, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error listing directory: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • Supporting utility function called by the list-directory handler to retrieve detailed file metadata including size, MIME type, binary detection, and encoding for each file found.
    static getFileInfo(filePath: string) { const stats = fs.statSync(filePath); const ext = path.extname(filePath); const buffer = fs.readFileSync(filePath); // Detect MIME type let mimeType = this.getMimeTypeFromExtension(ext); if (fileType.fileTypes) { for (const [type, signature] of Object.entries(fileType.fileTypes)) { if (Array.isArray(signature) && buffer.length >= signature.length && signature.every((byte, i) => buffer[i] === byte)) { mimeType = `image/${type}`; break; } } } const isBinary = this.isBinaryFile(buffer); let encoding: string | undefined; // Try to detect encoding for text files if (!isBinary) { try { // Try UTF-8 first const content = buffer.toString('utf8'); if (this.isValidUtf8(content)) { encoding = 'utf8'; } else { // Try other common encodings const encodings = ['ascii', 'utf16le', 'latin1']; for (const enc of encodings) { try { iconv.decode(buffer, enc); encoding = enc; break; } catch { continue; } } } } catch { // If all encoding detection fails, default to binary } } return { path: filePath, size: stats.size, created: stats.birthtimeMs, modified: stats.mtimeMs, mimeType, extension: ext, isBinary, encoding }; }

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/zad0xlik/ratespot-mcp'

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