Skip to main content
Glama
jbroll

MCP Build Environment Service

by jbroll

ls

List files and directories within a repository to inspect project structure and contents. Supports branch isolation for secure file browsing in build environments.

Instructions

List files and directories in a repository. Limited to paths within the repository to prevent path traversal. If branch is specified, creates/uses a hidden worktree (.repo@branch) for isolation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNoArguments to pass to ls (e.g., '-la', '-lh build/')
repoYesRepository name (required)
branchNoGit branch name (optional). If provided, uses isolated worktree.

Implementation Reference

  • The handler function that implements the core logic of the 'ls' tool: parses input arguments, validates them, constructs the 'ls' shell command, executes it within the specified repository worktree (handling branch-specific isolation and locking), and returns the output.
    async def handle_ls(self, args: Dict[str, Any]) -> List[TextContent]:
        """Handle ls command"""
        repo = args.get("repo")
        branch = args.get("branch")
        ls_args = args.get("args", "")
    
        # Validate arguments
        validate_ls_args(ls_args)
    
        # Build command
        cmd = ["ls"]
        if ls_args:
            cmd.extend(shlex.split(ls_args))
    
        # Execute in appropriate worktree with locking
        result = await self.execute_in_worktree(repo, branch, cmd)
        return [TextContent(type="text", text=result)]
  • The tool schema definition returned by list_tools(), including name, description, and JSON inputSchema specifying required 'repo' and optional 'args'/'branch' parameters.
    Tool(
        name="ls",
        description="List files and directories in a repository. "
                   "Limited to paths within the repository to prevent path traversal. "
                   "If branch is specified, creates/uses a hidden worktree (.repo@branch) for isolation.",
        inputSchema={
            "type": "object",
            "properties": {
                "args": {
                    "type": "string",
                    "description": "Arguments to pass to ls (e.g., '-la', '-lh build/')"
                },
                "repo": {
                    "type": "string",
                    "description": "Repository name (required)"
                },
                "branch": {
                    "type": "string",
                    "description": "Git branch name (optional). If provided, uses isolated worktree."
                }
            },
            "required": ["repo"]
        }
    ),
  • src/server.py:459-460 (registration)
    Tool dispatch/registration in the central execute_tool() method, which routes 'ls' calls to the handle_ls handler.
    elif name == "ls":
        return await self.handle_ls(arguments)
  • Helper function validate_ls_args() that checks 'ls' arguments for dangerous patterns (path traversal, shell injection), validates flags, and sanitizes paths to prevent escapes.
    def validate_ls_args(args: str) -> None:
        """
        Validate ls command arguments
    
        Args:
            args: Ls command arguments
    
        Raises:
            ValueError: If arguments contain dangerous patterns
        """
        if not args:
            return  # Empty args is fine (will list current directory)
    
        # Check for dangerous patterns
        if contains_dangerous_pattern(args):
            raise ValueError(f"Ls arguments contain dangerous patterns: {args}")
    
        # Parse arguments to validate paths
        parts = args.split()
        for part in parts:
            # Skip flags (starting with -)
            if part.startswith('-'):
                # Validate flag is reasonable
                if not re.match(r'^-[a-zA-Z]+$', part):
                    raise ValueError(f"Invalid ls flag: {part}")
                continue
    
            # Validate paths
            validate_path(part)
Behavior4/5

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

With no annotations provided, the description carries full burden and adds valuable behavioral context beyond basic functionality: it discloses security constraints ('Limited to paths within the repository to prevent path traversal') and implementation details about isolation worktrees. It doesn't cover error handling or output format, but provides meaningful operational insights.

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 perfectly front-loaded with the core purpose in the first sentence, followed by important behavioral details. Every sentence earns its place: the first establishes purpose, the second adds security context, and the third explains branch parameter implications. No wasted words.

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

Completeness4/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 does well for a 3-parameter tool: it covers purpose, security constraints, and branch behavior. However, it doesn't describe the return format (e.g., what the listing output looks like) or error conditions, leaving some gaps for the agent to infer.

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?

Schema description coverage is 100%, so the schema already documents all three parameters thoroughly. The description adds minimal parameter semantics - it only clarifies the branch parameter's effect on worktree isolation, but doesn't enhance understanding of 'args' or 'repo' beyond what the schema provides.

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

Purpose5/5

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

The description clearly states the specific action ('List files and directories') and resource ('in a repository'), distinguishing it from siblings like 'list' (which might be generic) and 'read_file' (which reads content). It provides explicit scope details that differentiate its functionality.

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

Usage Guidelines4/5

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

The description provides clear context for when to use the tool (listing repository contents) and mentions the branch parameter's effect (creates/uses hidden worktree for isolation). However, it doesn't explicitly state when NOT to use it or name alternatives among siblings like 'git' or 'list' for similar tasks.

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/jbroll/mcp-build'

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