Skip to main content
Glama
AbdurRaahimm

MCP Terminal & Git Server

by AbdurRaahimm

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);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions checking existence and listing contents, but lacks details on permissions needed, error handling (e.g., if path doesn't exist), output format, or rate limits. This is a significant gap for a tool that interacts with the filesystem.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core functionality ('Check if a directory exists and list its contents'). There is zero waste, and every word earns its place by clearly stating the tool's purpose without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a filesystem interaction tool. It doesn't explain what the return values are (e.g., boolean existence plus array of contents), error conditions, or behavioral traits like whether it recursively lists subdirectories. This leaves gaps for an AI agent to use it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the parameter 'path' clearly documented as 'Directory path to check'. The description adds no additional meaning beyond this, such as path format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('check if exists' and 'list contents') and resource ('directory'). It distinguishes from siblings like 'execute_command' or 'git_clone' by focusing on directory inspection rather than execution or project setup. However, it doesn't explicitly differentiate from potential similar tools (none present in siblings).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., path must be accessible), exclusions (e.g., not for file checking), or comparisons to sibling tools like 'open_in_vscode' for directory navigation. Usage is implied but not explicitly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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