Skip to main content
Glama
abhishekbhakat

mcp-server-code-assist

list_directory

Lists directory contents to view files and folders at a specified path, enabling navigation and management of file structures.

Instructions

Lists directory contents using system ls/dir command

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • The core handler function for the 'list_directory' tool. Validates the path, checks if it's a directory, executes the appropriate system command ('ls -la' on Unix or 'dir' on Windows), and returns the raw output as a string.
    async def list_directory(self, path: str) -> str:
        """List contents of a directory using system ls/dir command.
    
        Args:
            path: Directory path to list
    
        Returns:
            Raw command output as string
        """
        path = await self.validate_path(path)
        if not path.is_dir():
            raise ValueError(f"Path {path} is not a directory")
    
        if sys.platform == "win32":
            cmd = ["dir", path]
        else:
            cmd = ["ls", "-la", path]
    
        proc = await asyncio.create_subprocess_exec(*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
        stdout, _ = await proc.communicate()
        return stdout.decode()
  • Pydantic BaseModel defining the input schema for the 'list_directory' tool, specifying a 'path' parameter of type str or Path.
    class ListDirectory(BaseModel):
        path: str | Path
  • Tool registration in the @server.list_tools() handler, defining the tool name, description, and input schema.
        name=CodeAssistTools.LIST_DIRECTORY,
        description="Lists directory contents using system ls/dir command",
        inputSchema=ListDirectory.model_json_schema(),
    ),
  • Tool invocation handler in the @server.call_tool() function, which parses arguments using the schema, calls the dir_tools.list_directory method, and returns the result as TextContent.
    case CodeAssistTools.LIST_DIRECTORY:
        model = ListDirectory(path=arguments["path"])
        result = await dir_tools.list_directory(model.path)
        return [TextContent(type="text", text=result)]
  • Helper method used by list_directory to validate and resolve the input path, ensuring it's within allowed directories.
    async def validate_path(self, path: str) -> Path:
        """Validate and resolve path.
    
        Args:
            path: Path to validate
    
        Returns:
            Resolved Path object
    
        Raises:
            ValueError: If path is outside allowed directories
        """
        abs_path = os.path.abspath(path)
        if not any(abs_path.startswith(p) for p in self.allowed_paths):
            raise ValueError(f"Path {path} is outside allowed directories")
        return Path(abs_path)
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions using 'system ls/dir command', which implies platform-specific behavior (Unix vs. Windows) and potential command-line output formatting, but doesn't disclose critical details like error handling, permissions required, output format, or whether it's read-only (though implied by 'Lists'). This leaves significant gaps in behavioral understanding.

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 directly states the tool's function without unnecessary words. It's front-loaded with the core action and includes a useful implementation detail, making it highly concise and well-structured.

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, no output schema, and low schema coverage, the description is incomplete for a tool that interacts with the filesystem. It lacks details on output format, error conditions, permissions, and how it differs from siblings like 'file_tree'. For a directory listing tool, this leaves the agent with insufficient context to use it effectively.

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 0%, with one parameter 'path' undocumented in the schema. The description adds no specific meaning about the parameter beyond what's implied by the tool name (e.g., it doesn't clarify if 'path' is absolute/relative, supports wildcards, or has default values). However, with only one parameter and a straightforward purpose, the baseline is met but not exceeded.

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 action ('Lists directory contents') and the resource ('directory'), with the specific implementation detail 'using system ls/dir command' adding precision. However, it doesn't explicitly differentiate from sibling tools like 'file_tree' or 'read_file', which might have overlapping functionality for directory inspection.

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. With siblings like 'file_tree' that might also list directory contents, there's no indication of when this tool is preferred or what its specific scope or limitations are compared to others.

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/abhishekbhakat/mcp_server_code_assist'

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