create_temp_directory
Generate a temporary directory to store index data for efficient code repository analysis and search within the code-index-mcp server.
Instructions
Create the temporary directory used for storing index data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/code_index_mcp/server.py:288-292 (handler)MCP tool handler and registration for 'create_temp_directory'. This decorated function serves as the entry point for the tool execution, delegating the core logic to the manage_temp_directory helper function.@mcp.tool() @handle_mcp_tool_errors(return_type='dict') def create_temp_directory() -> Dict[str, Any]: """Create the temporary directory used for storing index data.""" return manage_temp_directory('create')
- Core helper function implementing the temporary directory creation logic for the MCP tool. Handles directory path resolution, creation using os.makedirs indirectly via ProjectSettings, and returns structured status information.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) )
- Alternative or supporting implementation of temp directory creation in SettingsTool class. Similar logic but direct os.makedirs call.def create_temp_directory(self) -> Dict[str, Any]: """ Create the temporary directory for settings. Returns: Dictionary with creation results """ temp_dir = self.get_temp_directory_path() existed_before = os.path.exists(temp_dir) try: os.makedirs(temp_dir, exist_ok=True) return { "temp_directory": temp_dir, "exists": os.path.exists(temp_dir), "is_directory": os.path.isdir(temp_dir), "existed_before": existed_before, "created": not existed_before } except (OSError, IOError) as e: return { "temp_directory": temp_dir, "exists": False, "error": str(e) }