Skip to main content
Glama

check_directory

Verify directory existence and display contents to validate file structure and locate files within specified paths.

Instructions

Check if a directory exists and list its contents

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesDirectory path to check

Implementation Reference

  • The handler for the 'check_directory' tool. Resolves the input path, checks if it is a directory using fs.stat, lists its contents with fs.readdir if it is a directory, and returns appropriate text content blocks for success or error cases.
    case "check_directory": { const { path: dirPath } = args as { path: string }; const resolvedPath = resolvePath(dirPath); try { const stats = await fs.stat(resolvedPath); if (!stats.isDirectory()) { return { content: [ { type: "text", text: `${resolvedPath} exists but is not a directory`, }, ], }; } const files = await fs.readdir(resolvedPath); return { content: [ { type: "text", text: `Directory ${resolvedPath} exists and contains:\n${files.join("\n")}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Directory ${resolvedPath} does not exist`, }, ], }; } }
  • src/index.ts:211-224 (registration)
    Registration of the 'check_directory' tool in the ListToolsRequestSchema handler, including name, description, and input schema.
    { name: "check_directory", description: "Check if a directory exists and list its contents", inputSchema: { type: "object", properties: { path: { type: "string", description: "Directory path to check", }, }, required: ["path"], }, },
  • Input schema definition for the 'check_directory' tool, specifying a required 'path' string parameter.
    inputSchema: { type: "object", properties: { path: { type: "string", description: "Directory path to check", }, }, required: ["path"], },
  • Helper function 'resolvePath' used by the check_directory handler to resolve user-provided paths, handling '~' expansion and absolute resolution.
    function resolvePath(inputPath: string): string { if (inputPath.startsWith("~")) { return path.join(os.homedir(), inputPath.slice(1)); } return path.resolve(inputPath); }

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/AbdurRaahimm/mcp-git-terminal-server'

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