make_directory
Create directories in Modal sandbox environments to organize files and prepare for operations. Specify path and optional parent directory creation.
Instructions
Creates a new directory in the sandbox.
Parameters:
- sandbox_id: The unique identifier of the sandbox
- path: Directory path to create in the sandbox
- parents: Whether to create parent directories if they don't exist
Returns a SandboxMakeDirectoryResponse containing:
- success: Boolean indicating if directory creation was successful
- message: Descriptive message about the operation
- path_created: The path that was created
This tool is useful for:
- Setting up directory structures
- Preparing for file operations
- Organizing sandbox content
The tool will:
1. Verify sandbox exists and is running
2. Create directory at specified path
3. Return status of the operation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sandbox_id | Yes | ||
| path | Yes | ||
| parents | No |
Implementation Reference
- The asynchronous handler function that executes the make_directory tool logic: fetches the sandbox, checks if running, creates directory using modal_sandbox.mkdir.aio(), logs, and returns success response.async def make_directory(self, sandbox_id: str, path: str, parents: bool = False) -> SandboxMakeDirectoryResponse: # Get sandbox from Modal using from_id modal_sandbox = await modal.Sandbox.from_id.aio(sandbox_id) # Check if sandbox is running before creating directory sandbox_status = await modal_sandbox.poll.aio() if sandbox_status is not None: raise ToolError(f"Sandbox {sandbox_id} is not running") await modal_sandbox.mkdir.aio(path, parents=parents) logger.info(f"Created directory {path} in sandbox {sandbox_id}") return SandboxMakeDirectoryResponse( success=True, message=f"Directory {path} created successfully", path_created=path, )
- src/mcp4modal_sandbox/backend/mcp_server.py:136-139 (registration)Registration of the make_directory tool using FastMCP's mcp_app.tool decorator, specifying name, description from ToolDescriptions, bound to self.make_directory method.mcp_app.tool( name="make_directory", description=ToolDescriptions.MAKE_DIRECTORY, )(self.make_directory)
- Pydantic BaseModel defining the output schema/response structure for the make_directory tool.class SandboxMakeDirectoryResponse(BaseModel): success: bool message: str path_created: str
- Tool description string defining input parameters, output, and usage for the make_directory tool, used in registration.MAKE_DIRECTORY = """ Creates a new directory in the sandbox. Parameters: - sandbox_id: The unique identifier of the sandbox - path: Directory path to create in the sandbox - parents: Whether to create parent directories if they don't exist Returns a SandboxMakeDirectoryResponse containing: - success: Boolean indicating if directory creation was successful - message: Descriptive message about the operation - path_created: The path that was created This tool is useful for: - Setting up directory structures - Preparing for file operations - Organizing sandbox content The tool will: 1. Verify sandbox exists and is running 2. Create directory at specified path 3. Return status of the operation """