*/ public static function getDisabledTools(): array { $stored = get_option( self::OPTION_DISABLED_TOOLS, array() ); if ( ! is_array( $stored ) ) { return array(); } $valid = array(); foreach ( $stored as $name ) { if ( is_string( $name ) && 1 === preg_match( '/^[a-z0-9_]+$/', $name ) ) { $valid[] = $name; } } return array_values( array_unique( $valid ) ); } /** * Store the full set of tool names switched off for the whole store. * Saving the set that is already stored succeeds without a write: * `update_option()` answers false for an unchanged value, which is not a * storage failure. * * @param array $names Tool names, validated by the caller * ({@see \AIPT\Api\Mcp\McpToolSwitches::apply()}) against the tool catalog. * @return bool Whether the stored set now matches `$names`. */ public static function setDisabledTools( array $names ): bool { $unique = array_values( array_unique( array_map( 'strval', $names ) ) ); sort( $unique ); $current = self::getDisabledTools(); sort( $current ); if ( $current === $unique ) { return true; } return update_option( self::OPTION_DISABLED_TOOLS, $unique, false ); } /** * Clamp a requested daily limit to the valid range. * * @param int $value Requested value. * @return int */ private static function clamp( int $value ): int { if ( $value < 0 ) { return 0; } if ( $value > self::MAX_DAILY_LIMIT ) { return self::MAX_DAILY_LIMIT; } return $value; } }