Skip to main content
Glama
milkymap

MCP4Modal Sandbox

by milkymap

list_directory_contents

Explore and verify files in a Modal sandbox directory to manage content and debug file-related issues.

Instructions

        Lists contents of a directory in the sandbox.
        
        Parameters:
        - sandbox_id: The unique identifier of the sandbox
        - path: Directory path to list in the sandbox
        
        Returns a SandboxListDirectoryResponse containing:
        - contents: List of filenames/directories at the specified path
        
        This tool is useful for:
        - Exploring sandbox filesystem structure
        - Verifying file operations
        - Debugging file-related issues
        - Managing sandbox content
        
        The tool will:
        1. Verify sandbox and directory exist
        2. List all contents at specified path
        3. Return directory listing
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sandbox_idYes
pathYes

Implementation Reference

  • The handler function that implements the list_directory_contents tool. It retrieves the Modal sandbox, checks if it's running, lists the directory contents using modal_sandbox.ls.aio(path), logs the action, and returns a SandboxListDirectoryContentsResponse.
    async def list_directory_contents(self, sandbox_id: str, path: str) -> SandboxListDirectoryContentsResponse:
        # Get sandbox from Modal using from_id
        modal_sandbox = await modal.Sandbox.from_id.aio(sandbox_id)
        
        # Check if sandbox is running before listing directory
        sandbox_status = await modal_sandbox.poll.aio()
        if sandbox_status is not None:
            raise ToolError(f"Sandbox {sandbox_id} is not running")
        
        contents = await modal_sandbox.ls.aio(path)
        logger.info(f"Listed directory {path} in sandbox {sandbox_id}")
        
        return SandboxListDirectoryContentsResponse(
            contents=contents
        )
  • Pydantic BaseModel defining the response schema for the tool, which includes a list of strings representing the directory contents.
    class SandboxListDirectoryContentsResponse(BaseModel):
        contents: List[str]
  • Tool registration in the FastMCP application within the register_tools method, binding the name, description, and handler function.
    mcp_app.tool(
        name="list_directory_contents",
        description=ToolDescriptions.LIST_DIRECTORY_CONTENTS,
    )(self.list_directory_contents)
  • The descriptive docstring for the list_directory_contents tool used during registration.
    LIST_DIRECTORY_CONTENTS = """
            Lists contents of a directory in the sandbox.
            
            Parameters:
            - sandbox_id: The unique identifier of the sandbox
            - path: Directory path to list in the sandbox
            
            Returns a SandboxListDirectoryResponse containing:
            - contents: List of filenames/directories at the specified path
            
            This tool is useful for:
            - Exploring sandbox filesystem structure
            - Verifying file operations
            - Debugging file-related issues
            - Managing sandbox content
            
            The tool will:
            1. Verify sandbox and directory exist
            2. List all contents at specified path
            3. Return directory listing
            """
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 does well by disclosing behavioral traits: it describes the verification step ('Verify sandbox and directory exist'), the listing process, and the return format. It doesn't mention error handling, permissions, or rate limits, but provides solid operational context beyond basic functionality.

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

Conciseness4/5

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

Well-structured with clear sections (purpose, parameters, returns, use cases, process steps) and front-loaded key information. Some redundancy exists (parameters listed twice in different formats), but every sentence adds value and the length is appropriate for the tool's complexity.

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 provides good coverage: explains purpose, parameters, return format, use cases, and operational steps. It doesn't detail error conditions or response structure beyond mentioning 'SandboxListDirectoryResponse', but is reasonably complete for a directory listing tool.

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

Parameters4/5

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

With 0% schema description coverage, the description compensates by clearly explaining both parameters: sandbox_id as 'unique identifier of the sandbox' and path as 'Directory path to list in the sandbox'. This adds essential meaning beyond the bare schema, though it could provide more detail about path format or sandbox_id constraints.

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 tool's purpose with specific verb ('Lists') and resource ('contents of a directory in the sandbox'), distinguishing it from siblings like list_sandboxes (which lists sandboxes) or read_file_content_from_sandbox (which reads file contents). The opening sentence provides immediate clarity without redundancy.

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 'This tool is useful for:' section provides clear context for when to use it (exploring filesystem, verifying operations, debugging, managing content), helping differentiate from tools like execute_command or remove_path. However, it doesn't explicitly state when NOT to use it or name specific alternatives for overlapping use cases.

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/milkymap/mcp4modal_sandbox'

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