check_temp_directory
Verify the temporary directory storing index data to ensure proper functionality in code repository indexing, searching, and analysis.
Instructions
Check the temporary directory used for storing index data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"title": "check_temp_directoryArguments",
"type": "object"
}
Implementation Reference
- src/code_index_mcp/server.py:294-298 (handler)Handler function for the 'check_temp_directory' MCP tool. Decorated with @mcp.tool() for registration and executes the tool by calling 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 helper function implementing the directory check logic (action='check'). Called by the handler to perform existence check, content listing, subdirectory inspection, and formatting of the response using ResponseFormatter.def manage_temp_directory(action: str) -> Dict[str, Any]: """ Manage temporary directory operations. This is a standalone function that doesn't require project context. Handles the logic for create_temp_directory and check_temp_directory MCP tools. Args: action: The action to perform ('create' or 'check') Returns: Dictionary with directory information and operation results Raises: ValueError: If action is invalid or operation fails """ if action not in ['create', 'check']: raise ValueError(f"Invalid action: {action}. Must be 'create' or 'check'") # Try to get the actual temp directory from index manager, fallback to default try: index_manager = get_index_manager() temp_dir = index_manager.temp_dir if index_manager.temp_dir else os.path.join(tempfile.gettempdir(), SETTINGS_DIR) except: temp_dir = os.path.join(tempfile.gettempdir(), SETTINGS_DIR) if action == 'create': existed_before = os.path.exists(temp_dir) try: # Use ProjectSettings to handle directory creation consistently ProjectSettings("", skip_load=True) result = ResponseFormatter.directory_info_response( temp_directory=temp_dir, exists=os.path.exists(temp_dir), is_directory=os.path.isdir(temp_dir) ) result["existed_before"] = existed_before result["created"] = not existed_before return result except (OSError, IOError, ValueError) as e: return ResponseFormatter.directory_info_response( temp_directory=temp_dir, exists=False, error=str(e) ) 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