check_temp_directory
Verify the location and status of the temporary directory where index data is stored, ensuring proper setup for code indexing.
Instructions
Check the temporary directory used for storing index data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/code_index_mcp/server.py:486-490 (registration)MCP tool registration for check_temp_directory via @mcp.tool() decorator, delegates to manage_temp_directory('check')
@mcp.tool() @handle_mcp_tool_errors(return_type="dict") def check_temp_directory() -> dict[str, Any]: """Check the temporary directory used for storing index data.""" return manage_temp_directory("check") - Core logic for check_temp_directory: checks directory status, lists contents and subdirectories, returns formatted response
else: # action == 'check' result = ResponseFormatter.directory_info_response( temp_directory=temp_dir, exists=os.path.exists(temp_dir), is_directory=os.path.isdir(temp_dir) if os.path.exists(temp_dir) else False, ) result["temp_root"] = tempfile.gettempdir() # If the directory exists, list its contents if result["exists"] and result["is_directory"]: try: contents = os.listdir(temp_dir) result["contents"] = contents result["subdirectories"] = [] # Check each subdirectory for item in contents: item_path = os.path.join(temp_dir, item) if os.path.isdir(item_path): subdir_info = { "name": item, "path": item_path, "contents": os.listdir(item_path) if os.path.exists(item_path) else [], } result["subdirectories"].append(subdir_info) except (OSError, PermissionError) as e: result["error"] = str(e) return result - Low-level SettingsTool.check_temp_directory method that checks directory existence and lists subdirectory contents
def check_temp_directory(self) -> Dict[str, Any]: """ Check the status of the temporary directory. Returns: Dictionary with directory status information """ temp_dir = self.get_temp_directory_path() result = { "temp_directory": temp_dir, "temp_root": tempfile.gettempdir(), "exists": os.path.exists(temp_dir), "is_directory": os.path.isdir(temp_dir) if os.path.exists(temp_dir) else False } # If the directory exists, list its contents if result["exists"] and result["is_directory"]: try: contents = os.listdir(temp_dir) result["contents"] = contents result["subdirectories"] = [] # Check each subdirectory for item in contents: item_path = os.path.join(temp_dir, item) if os.path.isdir(item_path): subdir_info = { "name": item, "path": item_path, "contents": os.listdir(item_path) if os.path.exists(item_path) else [] } result["subdirectories"].append(subdir_info) except (OSError, PermissionError) as e: result["error"] = str(e) return result - ResponseFormatter.directory_info_response - formats the directory info response dictionary used by check_temp_directory
def directory_info_response( temp_directory: str, exists: bool, is_directory: bool = False, contents: Optional[List[str]] = None, subdirectories: Optional[List[Dict[str, Any]]] = None, error: Optional[str] = None ) -> Dict[str, Any]: """ Format directory information response. Args: temp_directory: Path to the directory exists: Whether the directory exists is_directory: Whether the path is a directory contents: List of directory contents subdirectories: List of subdirectory information error: Error message if operation failed Returns: Formatted directory info response """ response = { "temp_directory": temp_directory, "exists": exists, "is_directory": is_directory } if contents is not None: response["contents"] = contents if subdirectories is not None: response["subdirectories"] = subdirectories if error: response["error"] = error return response